how to dynamically change masterpage in asp.net mvc applica开发者_如何转开发tion. Like in ASP.Net it can be changed in Page_PreInit Event
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;
}
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.
精彩评论