Lab 3 - Get started with ASP.NET Core MVC and Visual Studio (Part 1).pdf

This preview shows page 1 - 4 out of 18 pages.

Design and Developing Application in Cloud (CT071-3-5-3-DDAC) Get started with ASP.NET Core and Visual Studio Level 3 Asia Pacific University of Technology & Innovation Page 1of 18Lab 3: Get started with ASP.NET Core and Visual Studio This tutorial teaches the basics of building an ASP.NET Core Razor Pages web app. Razor Pages is the recommended way to build UI for web apps in ASP.NET Core. Prerequisites Visual Studio 2017 version 15.7.3 or later with the following workloads: ASP.NET and web development.NET Core cross-platform development.NET Core 2.1 SDK or later a.Create a new project for web application (Revision) Estimation time for this section A: 10 Minutes 1.From Visual Studio, select File > New > Project. 2.Complete the New Projectdialog: In the left pane, tap .NET CoreIn the center pane, tap ASP.NET Core Web Application (.NET Core)Name the project "MVCFlowerShop" (It's important to name the project "MVCFlowerShop" so when you copy code, the namespace will match.) Tap OK3.Complete the New ASP.NET Core Web Application (.NET Core) - MVCFlowerShopdialog: In the version selector drop-down box select ASP.NET Core 2.1Select Web Application (Model-View-Controller)Tap OK. Tap F5to run the app in debug mode or Ctrl-F5in non-debug mode. The default template gives you working Home, Aboutand Contactlinks. The browser image above doesn't show these links. Depending on the size of your browser, you might need to click the navigation icon to show them. If you were running in debug mode, tap Shift-F5to stop debugging.
Design and Developing Application in Cloud (CT071-3-5-3-DDAC) Get started with ASP.NET Core and Visual Studio Level 3 Asia Pacific University of Technology & Innovation Page 2of 18b.Add a model to a Razor Pages app in ASP.NET Core. Estimation time for this section D: 30 Minutes In this section, you add classes for managing flowers in a database. You use these classes with Entity Framework Core (EF Core) to work with a database. EF Core is an object-relational mapping (ORM) framework that simplifies the data access code that you have to write. The model classes you create are known as POCO classes (from "plain-old CLR objects") because they don't have any dependency on EF Core. They define the properties of the data that are stored in the database. In this tutorial, you write the model classes first, and EF Core creates the database. 1.Add a data model In Solution Explorer, right click the Modelsfolder. Select Add> Class. Name the class Flowerand replace the contents of the Flower class with the following code: using System; using System.ComponentModel.DataAnnotations.Schema; namespace MVCFlowerShop.Models { public class Flower { public int ID { get; set; } public string FlowerName { get; set; } public DateTime FlowerProducedDate { get; set; } public string Type { get; set; } public decimal Price { get; set; } } }
Design and Developing Application in Cloud (CT071-3-5-3-DDAC) Get started with ASP.NET Core and Visual Studio Level 3 Asia Pacific University of Technology & Innovation Page 3of 182.Scaffold the flower model

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture