如何告诉剃刀不要html逃生 [英] How to tell razor NOT to html escape

查看:63
本文介绍了如何告诉剃刀不要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(...).

这篇关于如何告诉剃刀不要html逃生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆