When adding a new view to an ASP.NET MVC 5 project using the Add View dialog pictured below, I'm invited to choose a template and a model class, which allows me to quickly generate a form for creating new instances of the model or a view that displays the model's properties. But why should the view care what the data context class is? In my project, whether or not I specify the data context class, the same view is generated, but I'm guessing there's a scenario where it would make a difference. What might that be?
Scaffolding in ASP.NET Core is a technique used to generate code at design time to support a number of common application scenarios when working with Entity Framework Core. The code generation tool is available as a Nuget package.
The @model directive allows access to the list of movies that the controller passed to the view by using a Model object that's strongly typed. For example, in the Index.cshtml view, the code loops through the movies with a foreach statement over the strongly typed Model object: CSHTML Copy.
Scaffolding is used to define the code-generation framework used in web applications. It uses T4 templates to generate basic controllers and views for the models. It generates instances for the mapped domain model and code for all CRUD operations.
If you refer to an existing DbContext then the wizard will insert public DbSet<Employee> Employee { get; set; }
(if it doesn't already exist) in your DbContext derived class . Looks like Visual Studio doing some of the leg work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With