开发者

how to dynamically change masterpage in asp.net mvc application

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜