How to specify default LayoutPage in Razor in ASP.NET MVC 3 Preview 1?

Viewed 12698

I want to specify (in one place) a default layout page in Razor, so that I can delete this:

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

from every .cshtml file I have. But I don't know how... Any ideas? I'm using Razor engine from ASP.NET MVC 3 Preview 1.

3 Answers

Create a "~/Views/_ViewStart.cshtml" page and the following inside:

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

Note that you can write code in here, so it is possible to change your layout based on the type of device targeted, etc.

This is now created by default in an empty MVC3 project.

Source

Related