4

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

there is not a whole lot different from what i have given the extensibility in mvc, i'm hoping there's another way
0

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

3 Comments

looks interesting will try it out !
worked for the master page have a theory on making the same change for the css too but will see it i have the time to implement it
hi, this link is broken, the blog has been moved here's the new url: developmentalmadness.com/archive/2009/06/09/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.