为什么HTML标题中的ASP.NET文本速记不呈现?

时间:2011-01-20 20:47:11

标签: asp.net-mvc

所以..这是我在MVC项目中的ASPX文件的上半部分:

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

现在div标签正确呈现样式表名称,但link-tag中的那个名称在写入时呈现,而不被解释。此外,还添加了路径前缀。

因此ASP.NET引擎似乎想要对链接标记中的href-argument中的文本进行麻烦,“帮助”我使用正确的相对路径为我的.css文件添加前缀。

  1. 为什么?你不觉得我自己能写出正确的道路吗?
  2. 我现在如何能以编程方式设置样式表的名称?

1 个答案:

答案 0 :(得分:2)

好开始

<%= ViewData[SomeNamespace.StyleSheetKey];" %>

需要

<%= ViewData[SomeNamespace.StyleSheetKey]; %>"

你的报价出错了。