2011-01-21 45 views
1

所以..这是在MVC2项目我的Site.Master ASPX文件的上半部分:如何在ASP.NET MVC 2项目中以编程方式设置样式表?

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

现在div标签呈现样式表名称正确,但一中的链接标签呈现为它被写入,而不被解释。另外还添加了一个路径前缀。

因此,ASP.NET引擎似乎想要在链接标签中的href参数中的文本“帮助”我的.css文件前缀正确的相对路径。

我现在怎样才能以编程方式设置样式表的名称?

+3

我现在是一个远射,但尝试删除runat =”服务器“标签 – 2011-01-21 08:12:56

+0

您先生,是赢家:-)发布它作为一个答案,而不是评论! – Nilzor 2011-01-21 08:28:40

回答

1

好吧,试着去掉RUNAT =“服务器“标记<head>标记

1

这将工作

<link href="<%= "" + ViewData[SomeNamespace.StyleSheetKey] %>" rel="stylesheet" type="text/css" /> 

但这并不

<link href="<%= (string)ViewData[SomeNamespace.StyleSheetKey] %>" rel="stylesheet" type="text/css" /> 

或者像The_Butcher说,从头部取出runat="server"

相关问题