2010-08-11 76 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 =「服務器」,它應該修復它。