In this video, the author explains how to create a movie model and controller from scratch in an MVC application. First, they demonstrate how to add a new class using the right-click models feature in the Solution Explorer. They give the class a couple of properties, such as an ID and name, using the 'prop' code snippet.
The movie class is a plain old CLR object (POCO) that represents the state and behavior of the application in terms of its problem domain. It does not have any behavior or logic, only properties that represent state.
Next, the author shows how to create a 'movies' controller with a 'random' action by right-clicking on the controllers in the Solution Explorer. They opt to create the controller from scratch rather than using a template.
The movies controller is a simple class that derives from the controller class. The author renames the default 'index' action to 'random' since it will be called when the user goes to '/movies/random'. In the 'random' action, an instance of the movie model is created with the name 'Shrek'.
At this point, the author explains that the view for the 'random' action does not exist and needs to be added. They right-click on the 'views' folder in the Solution Explorer, create a new 'random' view, and select the 'underline layout' as the layout for all views in the application.
In the view, the author changes the heading to display the name of the movie by using the 'model' property that gives access to the movie model passed from the controller. They also specify the type of the model using a directive at the top of the file.
Finally, the author runs the application to see the result of their work. They open the browser and navigate to '/movies/random'. The view displays the name of the movie, confirming that the model, view, and controller are working correctly. The author concludes the video by mentioning that more sophisticated scenarios will be covered in the rest of the course.
video txt