can i have multiple site.master files in asp.net mvc

只愿长相守 提交于 2019-12-07 04:23:10

问题


i have a number of files that i want to have the same "base" layout so i am using the site.master file for this and its working perfectly. but now i want another set of pages with a different "site.master" file. can i have multiple site.master files in one solution


回答1:


Yes. Just put the masters in the Shared folder along with the Site.master file and change the reference in the new View pages. You can do this by replacing the "Site.master" string for the Master Page or selecting the master page from the wizard when creating new views.




回答2:


You can create as many master pages as you want (with different names or locations). You can even have master pages with master pages.

BUT, a view can only use 1 master page.




回答3:


Yes. You can define the master page you want to use on top of every page or you can set this programmatically.




回答4:


Store the master page name inside the app settings and override the View method inside the Controller class.

 protected override ViewResult View(string viewName, string masterName, object model)   
     {

       return base.View(viewName,System.Web.Configuration.WebConfigurationManager.AppSettings["MasterPageName"], model);       
     }


来源:https://stackoverflow.com/questions/1284572/can-i-have-multiple-site-master-files-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!