_Viewstart Page in ASP.NET MVC 3

How to create _a Viewstart page?

Add a View named _ViewStart to the project. (Remember the name “_ViewStart” is important.).

Add a View

Note. If it already exists, do not add any more.

CS code

Let’s see its effect. There is no statement to include “Layout.cshtml”.

See its Effect

Run the application and watch the output.

Submit

This is because the Layout file is included on the “_ViewStart.cshtml“ page.

HTML

Let’s comment out the code line in the _ViewStart page run the application again and watch the output.

Client Object

Run the application.

Insert

Note. You can also explicitly add the Layout.cshtml page to the Target page.

Target page

The Benefit of the _ViewStart.cshtml page

So remove the Layout page and the declaration from individual pages and put it in the “_ViewStart.cshtml” page only.

Layout page

Watch the difference

Watch the difference

Run the application

MVC Application