views:

420

answers:

4

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

+4  A: 

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.

andymeadows
It doesn't have to be in the Shared folder, does it?
Martin
Not that I've seen. It's just put there as a default from everything I've read, observed and practiced.
andymeadows
+1  A: 

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

Scharrels
+1  A: 

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.

Martin
A: 

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)

{

System.Web.Configuration.WebConfigurationManager.AppSettings["MasterPageName"], model);

}

Oops, typo. The line should be this:return base.View(viewName, System.Web.Configuration.WebConfigurationManager.AppSettings["MasterPageName"], model);
Please consider editing your answer so that the code is appropriately formatted. To do this, put four spaces before each line and indent accordingly.
Dan Atkinson
Also, you can edit your answer with the comment you made. :)
Dan Atkinson