如何prevent在剃刀(独立的)逃跑的html? [英] How to prevent escaping html in Razor (standalone)?

查看:113
本文介绍了如何prevent在剃刀(独立的)逃跑的html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性内容,其中包含HTML字符串模型。

I have a Model with property Content which contains HTML string.

var model = new { Content = ... }
Razor.Parse(templateBody, model)

使用独立的剃刀我如何呈现这个字符串。

How can I render this string using standalone Razor.

我想:

@(new HtmlString(Model.Content))

和也

@(HttpUtility.HtmlDecode(Model.Content))

Model.Content始终呈现HTML转义。

Model.Content renders always HTML-escaped.

推荐答案

在RazorEngine库中特殊的拒收逃生我的类型是 RazorEngine.Text.IEn codedString 。使用简单的辅助方法对模板的基类:

In RazorEngine library special "do-not-escape-me" type is RazorEngine.Text.IEncodedString. Use simple helper method on template base class:

 @Raw("<script>alert('!');</script>")

要说服VS和ReSharper的给你智能感知在模板的顶部添加以下行:

To convince VS and Resharper to give you IntelliSense add following line at the top of template:

@inherits RazorEngine.Templating.TemplateBase

这篇关于如何prevent在剃刀(独立的)逃跑的html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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