1

我有以下行:

<link href="<%= Links.Content.Site_css %>" rel="stylesheet" type="text/css" />

呈现为

<link href="Views/Shared/%3C%25=%20Links.Content.Site_css%20%25%3E" rel="stylesheet" type="text/css" />

所以不执行表达式。如果我删除引号:

<link href=<%= Links.Content.Site_css %> rel="stylesheet" type="text/css" />

表达式被执行,但标记变得 xhtml 不兼容。解决此问题的正确方法是什么?

4

3 回答 3

4

只需删除标签上的 runat="server" 即可修复它。

于 2010-08-11T19:45:43.207 回答
2

使用单引号而不是双引号。

<link href='<%= Links.Content.Site_css %>' rel="stylesheet" type="text/css" />

对于这种特殊情况,我将使用CssMVC 期货程序集中的辅助方法:

<%:Html.Css(Links.Content.Site_css) %>
于 2010-08-11T19:24:02.247 回答
-1

这可能是一种解决方法

<link href=<%= '"' + Links.Content.Site_css + '"' %> rel="stylesheet" type="text/css" />

(我没有使用 ASP 的经验,如果这只是无效的语法,我很抱歉)

于 2010-08-11T19:19:30.980 回答