问题
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