views:

281

answers:

1

I'm designing an MVC site, and I've already got quite a few things in the Site.css that only apply to one controller or even one page. I'd like to break this out into multiple css files and include them only when necessary, but how can I do this when all header information is in the Site.Master.

Note: I still want to use master pages, I just want some header resources to be per page or per controller.

+4  A: 

I was able to do this by adding a ContentPlaceHolder into my Site.master header and then linking to the CSS statements via that placeholder. It works well from what I've seen.

Example:

<head runat="server">
  <title>Site Master</title>
  <asp:ContentPlaceHolder ID="css" runat="server" />
  <link href="~/css/css.css" type="text/css" rel="stylesheet" />
</head>

Something else to consider - if you have a lot of "one-off" CSS styles, you may want to think about how you're setting up the styles in the first place.

JasCav
I think that's the common technique. You can link javascripts and set titles (or add any other HEAD declarations) for each page specifically this way.
PanJanek
Thanks for the css link, that helps too!
C. Ross