开发者

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:

   &lt;script type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

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 ...");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜