如何在ASP.NET MVC 2项目的编程设置样式表?

问题描述:

所以..这是我的Site.Master ASPX文件在MVC2项目上半部分:

So.. this is the upper part of my site.master ASPX file in an MVC2 project:

<head runat="server">
   <link href="<%= ViewData[SomeNamespace.StyleSheetKey]; %>" rel="stylesheet" type="text/css" />
</head>
<div foo="<%= (string) ViewData[SomeNamespace.StyleSheetKey] %>">bar</div>

现在div标签呈现样式名称正确,但因为它是写一个在链接标签被渲染,而不间preTED。另外的路径preFIX加入。

Now the div tag renders the stylesheet name properly, but the one in the link-tag is rendered as it is written, without being interpreted. In addition a path prefix is added.

因此​​,ASP.NET引擎似乎想用在link标签的href-参数文本麻烦,帮我$ ​​P $ PFIX我的.css文件用正确的相对路径。

So the ASP.NET engine seems to want to hassle with the text in the href- argument in the link tag, "helping" me to prefix my .css file with the correct relative path.

如何将现在能够以编程设定的样式表的名称?

How will I now be able to set the name of the style sheet programmatically?

好吧,尝试删除=服务器,从标签中的&LT; HEAD&GT; 标记

Ok, Try removing the runat="server" tag from the <head> tag