Reputation: 10448
how to dynamically change masterpage in asp.net mvc application. Like in ASP.Net it can be changed in Page_PreInit Event
Upvotes: 4
Views: 2693
Reputation: 12082
You can create your own custom ViewPage
class, and override the OnPreInit
method and set the MasterPageFile
property accordingly.
Just change your Views to use your own custom ViewPage class, and you're done.
Upvotes: 1
Reputation: 29041
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;
}
Upvotes: 2