What is ViewStart?

_ViewStart.cshml page is used to serve common layout page(s) for a group of views. The code within this file is executed before the code in any view placed in the same directory. This file is also recursively applied to any view within a subdirectory.
By default ASP.NET MVC project has a _ViewStart.cshtml file in the Views directory and it specifies a default layout for your ASP.NET MVC application as shown below:

@{
    Layout = "~/Views/Shared/Layout.cshtml";
}

Since this code runs before any view, hence a view can override the Layout property and choose a different layout.

Tagged , . Bookmark the permalink.

Leave a Reply