tags:

views:

2336

answers:

4

I want allow the user to customize their web pages on my ASP.NET MVC website, so they can use their own style sheet. In MVC, the stylesheet link is placed in the section of the master page. How can I dynamically link to CSS in master page based on the user (that is, I will look up my table to find the CSS for a specific user and link to it).

Thanks!

+1  A: 

I would use a ContentPlaceHolder in the tag (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.contentplaceholder.aspx) for the master page and apply the data you want per the View you're showing.

Chris Missal
A: 

Thanks! I didn't know I can use the ContentPlaceHolder everywhere in the master page.

ycseattle
+1  A: 

I would have your view specific view models inherit from a common base view model, then have a property on this base view model that gets set in your controllers. Your masterpage can then set the correct css link dynamically without having to repeat code in a ContentPlaceHolder on every single view.

Luke Smith
A: 

how about using the old school passing the path to your custom controller in the src tag

with your MyCssController redirecting to the custom path based on your logic ??

Kumar