Reputation: 18603
So.. this is the upper part of my site.master ASPX file in an MVC2 project:
<head runat="server">
<link href="<%= ViewData[SomeNamespace.StyleSheetKey]; %>" rel="stylesheet" type="text/css" />
</head>
<div foo="<%= (string) ViewData[SomeNamespace.StyleSheetKey] %>">bar</div>
Now the div tag renders the stylesheet name properly, but the one in the link-tag is rendered as it is written, without being interpreted. In addition a path prefix is added.
So the ASP.NET engine seems to want to hassle with the text in the href- argument in the link tag, "helping" me to prefix my .css file with the correct relative path.
How will I now be able to set the name of the style sheet programmatically?
Upvotes: 1
Views: 1470
Reputation: 24532
This will work
<link href="<%= "" + ViewData[SomeNamespace.StyleSheetKey] %>" rel="stylesheet" type="text/css" />
but this doesn't
<link href="<%= (string)ViewData[SomeNamespace.StyleSheetKey] %>" rel="stylesheet" type="text/css" />
Or as The_Butcher says, remove the runat="server"
from the header
Upvotes: 1