繁体   English   中英

如何防止在Razor(独立)中转义html?

[英]How to prevent escaping html in Razor (standalone)?

我有一个带有属性Content的Model,其中包含HTML字符串。

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

如何使用独立Razor渲染此字符串。

我试过了:

@(new HtmlString(Model.Content))

并且

@(HttpUtility.HtmlDecode(Model.Content))

Model.Content渲染始终是HTML转义的。

这应该工作Html.Raw(Model.Content)

在RazorEngine库中,特殊的“do-not-escape-me”类型是RazorEngine.Text.IEncodedString 在模板基类上使用简单的辅助方法:

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

要说服VS和Resharper为您提供IntelliSense,请在模板顶部添加以下行:

@inherits RazorEngine.Templating.TemplateBase

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM