2010-08-11 75 views
1

我有以下行:ASP.NET MVC表达呈现 “原样”

<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不兼容。什么是解决这个问题的正确方法?

回答

2

使用单引号。

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

对于这种特殊情况,我会使用从MVC期货组装Css helper方法:

<%:Html.Css(Links.Content.Site_css) %> 
-1

这可能是一个解决办法

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

(我有ASP没有经验,对不起,如果这只是无效的语法),而不是双引号的

4

只是删除你的标记RUNAT =“服务器”,它应该修复它。