代码之家  ›  专栏  ›  技术社区  ›  SiberianGuy

ASP.NET MVC表达式按“原样”呈现

  •  1
  • SiberianGuy  · 技术社区  · 15 年前

    <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" />
    

    3 回复  |  直到 15 年前
        1
  •  2
  •   Necros    15 年前

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

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

    对于那个特殊情况,我会用 Css 来自MVC程序集的帮助程序方法:

    <%:Html.Css(Links.Content.Site_css) %>
    
        2
  •  4
  •   David Ebbo    15 年前

    只要删除标签上的runat=“server”,它就会修复它。

        3
  •  -1
  •   Bart van Heukelom    15 年前

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

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