开发者

how to dynamically change masterpage in asp.net mvc application

开发者 https://www.devze.com 2023-01-01 01:58 出处:网络
how to dynamically change masterpage in asp.net mvc applica开发者_如何转开发tion. Like in ASP.Net it can be changed in Page_PreInit EventViews expose the .MasterName property which specifies which mas

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号