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

If I have this in my Site.Master file:

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

      

and then go to the View Source section on my site page (when deploying to a real server), it displays the following:

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

      

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

Thank,

~ Justin

+2


source to share


2 answers


I always use the Url helper to be 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 it all with 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" ) ) %>

      

+6


source


The chapter has a runat = "server" option, which means that it runs this "magic" server side for link references. AFAIK this doesn't happen for script references.



+2


source







All Articles