开发者

Why I can't resolve client url for css files?

Here is my asp code:

<!-- 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>

And here it's the html rendered:

<!-- language: lang-js -->
<head>
    <title>Espace de travail</title>
    <link href="&lt;%: ResolveClientUrl(&quot;~/Content/Site.css&quot;) %>" rel="stylesheet" type="t开发者_StackOverflow社区ext/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>

Why asp can resolve url for my .js script file but not for my css file?


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

Use ResolveUrl or Url.Content helper method instead. The first link got encoded because of runat="server" attribute on head tag. Consider removing attribute or try this solution.


Try putting runat="server" on your <link> tag.


Try using <%= instead of <%:.


<%: automatically encodes the result string while <%= will display the exact text. If you use your original example and put <%= it will work.


This is the solution I used to get around the link tag issue:

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

Note how I put the entire link tag within an embedded code block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜