views:

862

answers:

2

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.

A: 

Here's interesting reading http://developmentalmadness.blogspot.com/2009/06/aspnet-mvc-discover-masterpagefile.html

Tadeusz Wójcik
looks interestingwill try it out !
Kumar
worked for the master pagehave a theory on making the same change for the css too but will see it i have the time to implement it
Kumar
hi, this link is broken, the blog has been moved here's the new url:http://www.developmentalmadness.com/archive/2009/06/09/aspnet-mvc-discover-masterpagefile.aspx
Mark J Miller
A: 

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.

James S
there is not a whole lot different from what i havegiven the extensibility in mvc, i'm hoping there's another way
Kumar