MVC3 Razor - Is there a way to change the layout depending on the browser request?

I successfully completed this lesson: http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx

All views are displayed successfully when accessing the page using a mobile device. But they are displayed in the wrong location (AKA main page).

I have the following structure: / Views / Shared / Mobile / _Layout.cshtml / Views / Shared / _Layout.cshtml

The problem is that in the view of EVERYONE I have to put the following statement:

Layout = "~/Views/Shared/Mobile/_Layout.cshtml";

Is there a place where I can put my logic to display one layout on another?

if (normalAccess) returns normal _Layout.cshtml else (mobileAccess) render / Mobile / _Layout.cshtml

I could not find where.

Thanks for any help.

+4
source share
1 answer

There's a good article at http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx

You can apparently create a file in the \ Views folder under the name _ViewStart.cshtml, where you can put your layout logic for use by all views

The _ViewStart.cshtml sample is simple:

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

: " _ViewStart.cshtml , , . : , , , , - /.

, , , 2010 , .

+7

All Articles