1

I can append a token to my script references like this:

<script type="text/javascript" src="/Some.js?<%= Html.GetToken() %>"></script>

... and this works fine. But, if I try to append the same token the same way to a CSS file reference:

<link rel="stylesheet" type="text/css" href="/Some.css?<%= Html.GetToken() %>" />

... the IIS generates the following markup:

<link rel="stylesheet" type="text/css" href="/Some.css?&lt;%= Html.GetToken() %>" />

I know I'm missing something super simple but I cannot see what exactly. Thanks in advance for any help!

1
  • Does your <head> section have runat="server" as orip suggested? Commented Aug 17, 2011 at 14:34

2 Answers 2

3

This happens if your <head> section has runat="server". If you can live without it (in ASP.NET MVC you usually can) try it this way.

If not, add or modify the CSS link in your view's Page_Load. If that sounds awful to you, then removing runat="server" should be working :)

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! That was it - runat in the head. Very strange, though. Looks like a bug in MS code, isn't it?
Dunno, in my experience WebForms templating has many unexpected behaviors in order to enable their complex features.
runat="server" tells asp.net that the tag is to be a server-side control. At that point you can no longer treat it like a literal and insert your inline values.
@shiznit123 - yeah, but why does it work with a <script> subelement but not with a <link> subelement? Just another HtmlHead quirk.
0

There a trick you can use for auto versioning.

Check out the post here:

Auto-versioning in ASP.NET MVC for CSS / JS Files?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.