Why is my custom HTML Helper result getting html encoded?
I've got the following custom html helper in asp.net mvc 3
public static string RegisterJS(this HtmlHelper helper, ScriptLibrary scriptLib)
{
return "<script type=\"text/javascript\"></script>\r\n";
}
The problem is that the result is getting html encoded like so (I had t开发者_Go百科o add spaces to get so to show the result properly:
<script type="text/javascript"></script>
This obviously isn't much help to me.. Nothing I've read says anything about this.. any thoughts on how I can get my real result back?
You're calling the helper in a Razor @
block or an ASPX <%: %>
block.
These constructs automatically escape their output.
You need to change the helper to return an HtmlString
, which will not be escaped:
return new HtmlString("<script ...");
精彩评论