ycseattle
ycseattle

Reputation: 3945

ASP.NET MVC: Link to CSS stylesheet dynamically in master page

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!

Upvotes: 2

Views: 4077

Answers (3)

Kumar
Kumar

Reputation: 11329

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 ??

Upvotes: 0

Luke Smith
Luke Smith

Reputation: 24244

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.

Upvotes: 2

Chris Missal
Chris Missal

Reputation: 6123

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.

Upvotes: 2

Related Questions