Creating the controller and actions
We have already seen that routing takes care of mapping the request URI to an action method in a controller, so let's further understand how the action methods then load the respective views. As you will have noticed, all the views in the ASP.NET Core MVC project are part of the Views
folder and when the action method execution is completed, it simply looks for Views/<ControllerName>/<Action>.cshtml
.
For example, an action method mapping to the Products/Index
route will load the Views/Products/Index.cshtml
view. This is handled by calling the Microsoft.AspNetCore.Mvc.Controller.View
method at the end of every action method.
The following screenshot shows a pictorial representation of this from our MVC application:
There are additional overloads and helper methods that can override this behavior and route to a different view as needed. Before we talk about...