ASP.NET Core MVC Interview Question #172
What is a custom view location and why might an application use one?
Testing, AJAX/JavaScript Integration, Localization & Advanced MVC Senior Advanced
Quick Interview Answer
MVC normally searches conventional view locations such as Views/{Controller}/{View}. An application can customize view-location expansion when it uses a different organizational convention, for example feature folders.
Detailed Explanation
MVC normally searches conventional view locations such as Views/{Controller}/{View}. An application can customize view-location expansion when it uses a different organizational convention, for example feature folders.
Custom locations can improve cohesion in a large codebase, but they add framework customization that new developers must understand. Standard conventions are preferable when they already meet the project's needs.
Code Example
builder.Services.AddControllersWithViews()
.AddRazorOptions(options =>
{
options.ViewLocationFormats.Add(
"/Features/{1}/Views/{0}.cshtml");
});