【问题标题】:Why I can't resolve client url for css files?为什么我无法解析 css 文件的客户端 URL?
【发布时间】:2011-06-06 03:16:45
【问题描述】:

这是我的 ASP 代码:

<!-- language: lang-js -->
<head runat="server">
    <title>
        <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
    </title>
    <link href='<%: ResolveClientUrl("~/Content/Site.css") %>' rel="stylesheet" type="text/css" />
    <script src='<%: ResolveClientUrl("~/Scripts/jquery.js")%>' type="text/javascript" />
    <script src='<%: ResolveClientUrl("~/Scripts/jquery-ui.js")%>' type="text/javascript" />
    <link href='<%: ResolveClientUrl("~/Content/redmond/jquery-ui.css") %>' rel="stylesheet" type="text/css" class="ui-theme" />
</head>

这里是渲染的 html:

<!-- language: lang-js -->
<head>
    <title>Espace de travail</title>
    <link href="&lt;%: ResolveClientUrl(&quot;~/Content/Site.css&quot;) %>" rel="stylesheet" type="text/css" />
    <script src='Scripts/jquery.js' type="text/javascript"></script>
    <script src='Scripts/jquery-ui.js' type="text/javascript"></script>
    <link href="&lt;%: ResolveClientUrl(&quot;~/Content/redmond/jquery-ui.css&quot;) %>" rel="stylesheet" type="text/css" class="ui-theme" />
</head>

为什么 asp 可以解析我的 .js 脚本文件的 url,但不能解析我的 css 文件?

【问题讨论】:

    标签: asp.net asp.net-mvc asp.net-mvc-2 asp.net-mvc-3


    【解决方案1】:

    The URL returned by this method is relative to the folder containing the source file in which the control is instantiated.

    改用ResolveUrlUrl.Content 辅助方法。由于head 标签上的runat="server" 属性,第一个链接被编码。考虑删除属性或尝试this solution

    【讨论】:

      【解决方案2】:

      尝试将runat="server" 放在您的&lt;link&gt; 标签上。

      【讨论】:

        【解决方案3】:

        尝试使用&lt;%= 而不是&lt;%:

        【讨论】:

          【解决方案4】:

          【讨论】:

          • 不,它不适用于
          【解决方案5】:

          这是我用来解决链接标签问题的解决方案:

          <%= "<link href=\"" + ResolveClientUrl( "~/Content/Site.css") + "\" rel=\"stylesheet\" type=\"text/css\" />" %>
          

          请注意我是如何将整个链接标签放在嵌入代码块中的。

          【讨论】:

            猜你喜欢
            • 2017-12-07
            • 2017-05-05
            • 2020-12-10
            • 1970-01-01
            • 2010-10-31
            • 1970-01-01
            • 2018-11-27
            • 2021-10-30
            • 2021-02-02
            相关资源
            最近更新 更多