【问题标题】:Why does the ASP.NET text shorthand in HTML header not render?为什么 HTML 标头中的 ASP.NET 文本速记不呈现?
【发布时间】:2011-01-20 20:47:11
【问题描述】:

所以..这是我在 MVC 项目中的 ASPX 文件的上半部分:

<head runat="server">
   <link href="<%= ViewData[SomeNamespace.StyleSheetKey];" %> rel="stylesheet" type="text/css" />
</head>
<div foo="<%= (string) ViewData[SomeNamespace.StyleSheetKey] %>">bar</div>

现在 div 标签正确地呈现了样式表名称,但链接标签中的那个在它被写入时被呈现,没有被解释。另外添加了一个路径前缀。

所以 ASP.NET 引擎似乎想要处理链接标签中 href 参数中的文本,“帮助”我为我的 .css 文件添加正确的相对路径前缀。

  1. 为什么?你不觉得我自己能写出正确的路径吗?
  2. 我现在如何能够以编程方式设置样式表的名称?

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    开始吧

    <%= ViewData[SomeNamespace.StyleSheetKey];" %>
    

    需要

    <%= ViewData[SomeNamespace.StyleSheetKey]; %>"
    

    你把引号放错地方了。

    【讨论】:

    • sigh 我的错,我在写这个问题时搞砸了,但在我的测试代码中没有 - 问题仍然像我描述的那样。我在stackoverflow.com/questions/4756641/… 发布了一个新问题
    猜你喜欢
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2015-01-20
    相关资源
    最近更新 更多