Every time I put an inline tag on the link’s href attribute it somehow gets auto-encoded. Is this ASP.NET’s default behavior? How can I dynamically set the Href attribute using code? This is in MVC btw.
Attempted something like this
<link href="<%: Link.Content.Jquery_css %>" rel="stylesheet" type="text/css" />
which rendered this (nothing changed)
<link href="<%: Link.Content.Jquery_css %>" rel="stylesheet" type="text/css" />
and this
<link href="<%= Link.Content.Jquery_css %> rel="stylesheet" type="text/css" />
which produced this (I couldn’t remember the exact numbers, but it seems the bracket-percent-equals was encoded to link format)
<link href="/View/Shared%25Link.Content.Jquery_css%25" %>" rel="stylesheet" type="text/css" />
Link.Content.Jquery_css is a strongly typed string containing the link made using T4MVC.
Add’l info: I used ASP.NET MVC 2, in .NET 4 and testing in Firefox.
It’s getting auto-encoded because of the tag your using (
<%: %>). If you don’t want the URL to be Encoded, use the following: