Why does the ASP.NET text shorthand in HTML header not render?
So.. this is the upper part of my ASPX file in an MVC 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 rende开发者_开发百科red 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.
- Why? Don't you think I'm able to write the correct path myself?
- How will I now be able to set the name of the style sheet programatically?
Well to start
<%= ViewData[SomeNamespace.StyleSheetKey];" %>
needs to be
<%= ViewData[SomeNamespace.StyleSheetKey]; %>"
You got the quotes in the wrong place.
精彩评论