开发者

CSS Files in ASP.NET MVC with a master page

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 开发者_如何学JAVAthis 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜