how to dynamically change masterpage in asp.net mvc application. Like in ASP.Net it can be changed in Page_PreInit Event
2 Answers
Views expose the .MasterName property which specifies which master page to use. You can set this in your controller when returning a view.
For example,
public ActionResult Index()
{
ViewResult vr = View();
vr.MasterName="....";
return vr;
}
3 Comments
mookid8000
true - or check out the various overloads of the
View method, two of them has the ability to specify which master page to render: msdn.microsoft.com/en-us/library/…Wim
If it's something you want to apply more generally and site wide, this may be way too laborious to have to apply this in each Action for a bunch of Views.
3Dave
@Wim good point. It may make more sense to create a common base controller class and adding this code to OnActionExecuted, or overriding/overloading the .View() method