javascript 如何告诉剃刀不要 html 转义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4463265/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell razor NOT to html escape
提问by sTodorov
I am using asp.net mvc 3 with razor for a project. At some I need to serialize an array from the controller, put it in the viewdata and assign it to a js object. However when I output it using
我正在为一个项目使用带有剃刀的 asp.net mvc 3。在某些情况下,我需要从控制器序列化一个数组,将其放入 viewdata 并将其分配给一个 js 对象。但是,当我使用输出它时
@ViewData["some array"]
The result is html escaped so i get something like :
结果是 html 转义,所以我得到类似的东西:
[{"title":"Something","id":"Something-1" etc'
With the <%= %> this was not escaped so it was behaving as expected. Is it possible to tell razor not to escape this string. Perhaps, someone might suggest another approach all together.
使用 <%= %> 这没有被转义,所以它的行为符合预期。是否可以告诉 razor 不要转义这个字符串。也许,有人可能会建议另一种方法。
Thanks in advance for any ideas
提前感谢您的任何想法
回答by SLaks
You need to output an instance of the new IHtmlStringinterface, which contains pre-escaped HTML.
您需要输出新IHtmlStringinterface 的一个实例,其中包含预转义的 HTML。
To do that write @Html.Raw(...).
要做到这一点写@Html.Raw(...)。

