我有一个带有属性Content的Model,其中包含HTML字符串 .
var model = new { Content = ... } Razor.Parse(templateBody, model)
如何使用独立Razor渲染此字符串 .
我试过了:
@(new HtmlString(Model.Content))
并且
@(HttpUtility.HtmlDecode(Model.Content))
Model.Content渲染始终是HTML转义的 .
在RazorEngine库中,"do-not-escape-me"类型为 RazorEngine.Text.IEncodedString . 在模板基类上使用简单的辅助方法:
RazorEngine.Text.IEncodedString
@Raw("<script>alert('!');</script>")
要说服VS和Resharper为您提供IntelliSense,请在模板顶部添加以下行:
@inherits RazorEngine.Templating.TemplateBase
这应该工作 Html.Raw(Model.Content)
Html.Raw(Model.Content)
2 回答
在RazorEngine库中,"do-not-escape-me"类型为
RazorEngine.Text.IEncodedString
. 在模板基类上使用简单的辅助方法:要说服VS和Resharper为您提供IntelliSense,请在模板顶部添加以下行:
这应该工作
Html.Raw(Model.Content)