ASP.NET Core MVC Interview Question #17
What is _ViewStart.cshtml?
MVC Fundamentals, Controllers, Views & Routing Junior Beginner
Quick Interview Answer
_ViewStart.cshtml contains Razor code that should run before views in its directory hierarchy. Its most common purpose is to specify the default Layout for multiple views without repeating the Layout assignment in every .cshtml file.
Detailed Explanation
_ViewStart.cshtml contains Razor code that should run before views in its directory hierarchy. Its most common purpose is to specify the default Layout for multiple views without repeating the Layout assignment in every .cshtml file.
A _ViewStart.cshtml file can exist at different folder levels, allowing more specific folders to override settings when needed.
Code Example
@{
Layout = "_Layout";
}