ASP.NET Core MVC Interview Question #11
Where does ASP.NET Core MVC look for views by convention?
MVC Fundamentals, Controllers, Views & Routing Junior Beginner
Quick Interview Answer
For a controller-specific view, MVC conventionally looks under Views/{ControllerName}/{ViewName}. It can also look under Views/Shared for views shared across controllers. For example, HomeController returning View() from its Index action normally resolves Views/Home/Index.cshtml.
Detailed Explanation
For a controller-specific view, MVC conventionally looks under Views/{ControllerName}/{ViewName}. It can also look under Views/Shared for views shared across controllers. For example, HomeController returning View() from its Index action normally resolves Views/Home/Index.cshtml.
The default conventions can be customized, but following the standard folder structure makes MVC applications easier to understand and maintain.
Code Example
// HomeController.Index()
return View();
// Typical locations:
// Views/Home/Index.cshtml
// Views/Shared/Index.cshtml