Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 524
Darmak Avatar asked Sep 11 '25 09:09

Darmak


1 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

like image 85
miguelv Avatar answered Sep 13 '25 11:09

miguelv