Scaffold the index view
Last updated
Last updated
Scaffolding is a feature of Visual Studio where we can generate code based on a given criterial or model. It saves a lot of time and efforts. Generated code can be customized as required. We could also do this task manually in case we prefer that for some reason.
Before that,
Make sure that the application is stopped and the app builds without any errors.
If Visual Studio prompts you to save the solution file, do so since we might have created a project only and going forward, we need a solution to hold configuration info as well!
Follow the steps shown below to first scaffold the views required to display a movie list. We will need various views - For CRUD operations:
Create a Movies folder under Views folder and then:
Click Add and then save the solution file if VS prompts for it.
In case your scaffolding did not go through, you can manually create this file:
The @model
statement at the top of the Index.cshtml
file:
The @model
directive allows access to the list of movies that the controller passes 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
Because the Model
object is strongly typed as an IEnumerable<Movie>
object, each item in the loop is typed as Movie
. Among other benefits, the compiler validates the types used in the code.