Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a bug? Or is it a setting in ASP.NET 4 (or MVC 2)?

I just recently started trying out T4MVC and I like the idea of eliminating magic strings.

However, when trying to use it on my master page for my stylesheets, I get this:

<link href="<%: Links.Content.site_css %>" rel="stylesheet" type="text/css" />

rending like this:

<link href="&lt;%: Links.Content.site_css %>" rel="stylesheet" type="text/css" />

Whereas these render correctly:

<link href="<%: Url.Content("~/Content/Site.css") %>" rel="stylesheet" type="text/css" />
<link href="<%: Links.Content.site_css + "" %>" rel="stylesheet" type="text/css" />

It appears that, as long as I have double quotes inside of the code segment, it works. But when I put anything else in there, it escapes the leading "less than".

Is this something I can turn off? Is this a bug?


Edit:

This does not happen for <script src="..." ... />, nor does it happen for <a href="...">.


Edit 2:

Minimal case:

<link href="<%: string.Empty %>" />

vs

<link href="<%: "" %>" />


Edit 3:

I have a workaround, I have implemented an HtmlHelper extension so that I can do this:

<%: Html.StyleSheet(Links.Content.site_css) %>

I like the support for intellisens better, so I'm actually going to stick with that. Right now, I'm just trying to solve the bug.

like image 856
John Gietzen Avatar asked Dec 21 '10 16:12

John Gietzen


1 Answers

It looks like a bug to me, the compiled output for that is:

private global::System.Web.UI.HtmlControls.HtmlLink @__BuildControl__control5() {
    global::System.Web.UI.HtmlControls.HtmlLink @__ctrl;            
    @__ctrl = new global::System.Web.UI.HtmlControls.HtmlLink();
    @__ctrl.Href = "<%: String.Empty %>";
    ((System.Web.UI.IAttributeAccessor)(@__ctrl)).SetAttribute("rel", "stylesheet");
    ((System.Web.UI.IAttributeAccessor)(@__ctrl)).SetAttribute("type", "text/css");
    return @__ctrl;
}

This seems to only happen when the control is inside a head runat="server"

like image 160
The Scrum Meister Avatar answered Nov 04 '22 07:11

The Scrum Meister