Adding Views

We were returning a simple string from the controller. Although that explains the concept of how the Controller and action method works, it is not of much practical use.

Let us create a new action method by the name, Index2:

public IActionResult Index2() { 
  return View(); // View for this 'Index2' action method 
} 

Now, we have created the action method that returns a View. But we still have not added the View for the same. By convention, ASP.NET MVC would try to search for our View in the folder Views\{ControllerName}\{ActionMethod.cshtml}. With respect to the preceding example, it will try to search for Views\Home\Index2.cshtml. Please note that the name of the controller folder-is Home , not HomeController. Only the prefix is needed ...

Get Learning ASP.NET Core MVC Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.