Question

I have an MVC4 application with two areas, "Reports" and "Admin". I want views in these areas to use the same _Layout that is used throughout the entire application (~/Shared/_Layout.cshtml). When I build the application and hit it on my dev workstation, both areas render correctly. However, when I publish it to Server 2008 R2 (running IIS 7.5), none of the views in the Admin area have the _Layout. I've switched browsers, tried both on the web server and hitting it from another system in the domain, clearing the cache....nothing has worked. Anyone know why this is happening?

Was it helpful?

Solution

In a current project I have an area and in this area's Views folder there's a file called _ViewStart.cshtml. Its Layout property points to the application level _Layout.cshtml file that's within the ApplicationName/Views/Shared folder.

_ViewStart.cshtml

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

Doing this you can share a common _Layout.cshtml file with all or only some of your Areas.


For more info about the _ViewStart.cshtml file be sure to check this answer:

https://stackoverflow.com/a/9300466/114029

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top