如何告诉剃刀不要html逃生

问题描述:

我在一个项目中使用带有剃刀的asp.net mvc 3. 在某些情况下,我需要从控制器序列化一个数组,将其放入viewdata中并将其分配给js对象.但是,当我使用

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"]

结果是html转义,所以我得到了类似的东西:

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.

预先感谢您的任何想法

您需要输出新的

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

为此,请写@Html.Raw(...).