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

4

5

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

Titus answered 16/8, 2009 at 15:40 Comment(0)
D
5

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.

Disorient answered 16/8, 2009 at 15:43 Comment(2)
It doesn't have to be in the Shared folder, does it?Aho
Not that I've seen. It's just put there as a default from everything I've read, observed and practiced.Disorient
A
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.

Aho answered 16/8, 2009 at 15:44 Comment(0)
C
1

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

Cyclist answered 16/8, 2009 at 15:43 Comment(0)
C
0

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);       
     }
Culpable answered 1/9, 2009 at 19:24 Comment(2)
Oops, typo. The line should be this: return base.View(viewName, System.Web.Configuration.WebConfigurationManager.AppSettings["MasterPageName"], model);Culpable
Please consider editing your answer so that the code is appropriately formatted. To do this, put four spaces before each line and indent accordingly.Planet

© 2022 - 2024 — McMap. All rights reserved.