I would like to use the _ViewStart page to set the master page (layout) used by the views. I have only two different layouts. One for the homepage and one for the other pages (but that may change)
I was hoping to add a dynamic property to the ViewModel object in the home page's controller method and then check for it. Something like this
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Marked as answer by paully_21 on Nov 30, 2010 05:29 PM
paully_21
Member
1 Points
10 Posts
_ViewStart.cshtml and conditional Layout pages
Nov 30, 2010 02:22 PM|LINK
Forgive me but I'm totally new to MVC.
I would like to use the _ViewStart page to set the master page (layout) used by the views. I have only two different layouts. One for the homepage and one for the other pages (but that may change)
I was hoping to add a dynamic property to the ViewModel object in the home page's controller method and then check for it. Something like this
_ViewStart =
@{ if (ViewModel.IsHomePage == true) { Layout = "~/Views/Shared/_HomeLayout.cshtml"; } else { Layout = "~/Views/Shared/_MainLayout.cshtml"; } }And in the HomeController Index() add this
ViewModel.IsHomePage = true;
I know this is wrong, but it's the functionality I am looking for. Any help here is appreciated.
Paul
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: _ViewStart.cshtml and conditional Layout pages
Nov 30, 2010 03:20 PM|LINK
@{
if (ViewContext.Controller.ViewModel.IsHomePage == true)
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
else
{
Layout = "~/Views/Shared/_MainLayout.cshtml";
}
}
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
paully_21
Member
1 Points
10 Posts
Re: _ViewStart.cshtml and conditional Layout pages
Nov 30, 2010 05:30 PM|LINK
Perfect...Thanks!