开发者

ASP.NET MVC Content folder - URLs changed in source for CSS/images but not for JS?

开发者 https://www.devze.com 2022-12-08 12:47 出处:网络
If I have this in my Site.Master file: <link href=\"../../Content/Site.css\" rel=\"stylesheet\" type=\"text/css\" />

If I have this in my Site.Master file:

<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />

and then go to View Source on page of 开发者_开发知识库my site (when deployed to actual server), it renders like this:

<link href="Content/Site.css" rel="stylesheet" type="text/css" />

But if I have a JS file in the Scripts/ folder, it doesn't mimic the same behavior. Where is the magic? Is there some setting somewhere that is causing this?

Thanks,

~ Justin


I always use the Url helper to make sure.

<link href="<%= Url.Content( "~/content/site.css" ) %>"
      rel="stylesheet"
      type="text/css" />

<script type="text/javascript"
        src="<%= Url.Content( "~/scripts/jquery-1.3.2.min.js" ) %>">
</script>

In fact, I've actually replaced this all by HtmlHelper extensions that do the same thing.

<%= Html.Stylesheet( Url.Content( "~/content/site.css ) ) %>
<%= Html.Javascript( Url.Content( "~/scripts/jquery-1.3.2.min.js" ) ) %>


The head has the runat="server" option set which means that it performs this "magic" server-side for link references. AFAIK this does not happen for scripts references.

0

精彩评论

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

关注公众号