In asp.net MVC 3 is there a way to override the Layout declaration set in a view from a controller or action filter?
@{ Layout = \"~/Views/Shared/_Layout.cshtm
Another place where you can control the layout is in the _ViewStart.cshtml
.
Here, you can do the logic you need and programatically specify which layout to use. This allows you to place the logic in only one place and keep it out of the view.
@{
if(myBusinessRule)
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
else
{
Layout = "~/Views/Shared/_SecondaryLayout.cshtml";
}
}
Blog post where it was introduced by Scott Gu