I was advised (by a person I cannot now contact to ask this) to use a query-string-trick to keep from caching a style sheet while I was debugging. The respondent said this would do the trick:
@{ var currentDate = DateTime.Now; }
<link href="@Url.Content("~/Styles/Site.css?" + currentDate)" rel="stylesheet" type="text/css" />
And I see why, but the expression @{ var currentDate = DateTime.Now; } is just resolving to the literal value in the page when I run it. The full code is:
<head runat="server">
<title></title>
@{ var currentDate = DateTime.Now; }
<link href="@Url.Content("~/Styles/Site.css?" + currentDate)" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
The syntax “@{ }” is new to me. I don’t see a reference to it in any doc that I have looked at. According to the usage it appears to be inline script, but it isn’t being treated as that at runtime, and I am not even sure if it is Active Server Page syntax (or PHP?).
What DOES work is:
<% var currentDate = DateTime.Now; %>
<link href="~/Styles/Site.css?<%= currentDate%>" rel="stylesheet" type="text/css" />
OK, but still, what does “@{ <some expression> }” signify?
It’s Razor, which is a newer rendering engine for asp.net. It’s doing the exact same thing as your <% %> block of code.