asp.net
  • asp.net-mvc
  • asp.net-mvc-2
  • asp.net-mvc-3
  • 2011-06-06 125 views 2 likes 
    2

    这里是我的ASP代码:为什么我无法解析css文件的客户端url?

    <!-- 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脚本文件,但不是我的CSS文件?

    回答

    4

    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

    +0

    +1对于使用Url.Content – ZippyV 2011-06-06 13:09:21

    +0

    好吧,你链接的解决方案......但是......为什么? – Tuizi 2011-06-06 14:29:54

    0

    尝试将runat="server"放在<link>标记上。

    0

    尝试使用<%=而不是<%:

    0

    <%:自动编码结果字符串,而<%=将显示确切的文本。如果你使用你原来的例子,并把<%=它会工作。

    +0

    Nop它不适用于<%=,好的解决方案是:Url.Content() – Tuizi 2011-06-07 14:51:56

    0

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

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

    注意我是如何把整个链接标签嵌入代码块中。

    相关问题