Reputation: 11329
Is there a good way to change the MasterPage and/or .css dynamically in asp.net mvc based on the user preferences?
I understand I can change the master name as follows:
return View("viewName", "master-name", oModel)
and the view using a different contentPlaceHolder perhaps but that requires changing each controller+action.
I'd have to assume there is to be a better way than this.
Upvotes: 4
Views: 4486
Reputation: 3374
I have a somewhat simpler method:
return View("View", getMasterName());
and in my master controller, I have:
protected string getMasterName() {
return (Request.QueryString["tb"] == null) ? null : "Other_Master";
}
I use it to display a different template in the case of a thickbox popup vs if, eg, javascript isn't working and the controller is loaded without thickbox.
Upvotes: 3
Reputation: 6317
Here's interesting reading http://developmentalmadness.blogspot.com/2009/06/aspnet-mvc-discover-masterpagefile.html
Upvotes: 0