How to tell razor NOT to html escape

空扰寡人 提交于 2019-12-31 10:57:33

问题


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

@ViewData["some array"]

The result is html escaped so i get something like :

[{"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.

Thanks in advance for any ideas


回答1:


You need to output an instance of the new IHtmlString interface, which contains pre-escaped HTML.

To do that write @Html.Raw(...).



来源:https://stackoverflow.com/questions/4463265/how-to-tell-razor-not-to-html-escape

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!