我有以下一行:
<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不兼容。解决这个问题的正确方法是什么?
答案 0 :(得分:4)
只需删除标记上的runat =“server”即可修复它。
答案 1 :(得分:2)
使用单引号而不是双引号。
<link href='<%= Links.Content.Site_css %>' rel="stylesheet" type="text/css" />
对于这种特殊情况,我将使用MVC期货装配中的Css
辅助方法:
<%:Html.Css(Links.Content.Site_css) %>
答案 2 :(得分:-1)
这可能是一种解决方法
<link href=<%= '"' + Links.Content.Site_css + '"' %> rel="stylesheet" type="text/css" />
(我没有使用ASP的经验,对不起,如果这只是无效的语法)