"
ASP.NET (snapshot 2017) Microsoft documentation and samples

[!INCLUDEadding-model1]

[!code-csharpMain]

   1:  //#define MovieNoEF
   2:  #if MovieNoEF
   3:  #region snippet_1
   4:  using System;
   5:   
   6:  namespace MvcMovie.Models
   7:  {
   8:      public class Movie
   9:      {
  10:          public int ID { get; set; }
  11:          public string Title { get; set; }
  12:          public DateTime ReleaseDate { get; set; }
  13:          public string Genre { get; set; }
  14:          public decimal Price { get; set; }
  15:      }
  16:  }
  17:  #endregion
  18:  #endif

The ID field is required by the database for the primary key.

Build the app to verify you don’t have any errors, and you’ve finally added a Model to your MVC app.

Prepare the project for scaffolding

Scaffold the MovieController

Open a terminal window in the project folder and run the following commands:

dotnet restore
dotnet aspnet-codegenerator controller -name MoviesController -m Movie -dc MvcMovieContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries 

[!NOTE] If you get an error when the scaffolding command runs, see issue 444 in the scaffolding repository for a workaround.

The scaffolding engine creates the following:

The automatic creation of CRUD (create, read, update, and delete) action methods and views is known as scaffolding. You’ll soon have a fully functional web application that lets you manage a movie database.

[!INCLUDEadding-model 2x]

[!INCLUDEadding-model]

You now have a database and pages to display, edit, update and delete data. In the next tutorial, we’ll work with the database.

Additional resources

Previous - Add a view Next - Working with SQLite



Comments ( )
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/tutorials/first-mvc-app-xplat/adding-model.htm
< THANKS ME>