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

[!INCLUDEadding-model]

Add the following properties to the Movie class:

[!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 project to verify you don’t have any errors. You now have a Model in 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 

If you get the error No executable found matching command "dotnet-aspnet-codegenerator", verify:

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.

Add the files to Visual Studio

[!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 Adding a View Next Working with SQL





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/tutorials/first-mvc-app-mac/adding-model.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>