I would like to have 2 separate Layouts in my application. Let's say one is for the Public section of the website and the other is for the Member side.
For simplicity, let's say all the logic for each of these sites is wrapped neatly into 2 distinct controllers.
And that they each have a corresponding Layout for all the View under each.
How do I use the _ViewStart.cshtml file to specify that all Views / Actions under "Public" use the PublicLayout and everything under "Staff" uses the StaffLayout?
This question is related to
asp.net-mvc
layout
asp.net-mvc-3
razor
One more method is to Define the Layout inside the View:
@{
Layout = "~/Views/Shared/_MyAdminLayout.cshtml";
}
More Ways to do, can be found here, hope this helps someone.
This method is the simplest way for beginners to control Layouts rendering in your ASP.NET MVC application. We can identify the controller and render the Layouts as par controller, to do this we can write our code in _ViewStart file in the root directory of the Views folder. Following is an example shows how it can be done.
@{
var controller = HttpContext.Current.Request.RequestContext.RouteData.Values["Controller"].ToString();
string cLayout = "";
if (controller == "Webmaster")
cLayout = "~/Views/Shared/_WebmasterLayout.cshtml";
else
cLayout = "~/Views/Shared/_Layout.cshtml";
Layout = cLayout;
}
Read Complete Article here "How to Render different Layout in ASP.NET MVC"
Source: Stackoverflow.com