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="<%: 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?
This does not happen for <script src="..." ... />
, nor does it happen for <a href="...">
.
Minimal case:
<link href="<%: string.Empty %>" />
vs
<link href="<%: "" %>" />
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With