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
can i have multiple site.master files in asp.net mvc
Asked Answered
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.
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
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.
Yes. You can define the master page you want to use on top of every page or you can set this programmatically.
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);
}
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.