使用RazorEngine时如何输出原始html(不是来自MVC) [英] How do I output raw html when using RazorEngine (NOT from MVC)
问题描述
我正在尝试生成具有HTML内容的电子邮件.该内容已经过卫生处理,因此我对此并不担心,但是当我打电话给
I am trying to generate emails with HTML content. this content has already gone through sanitation so I am not worried in that regard, however when I call:
Razor.Parse(template, model);
在以下Razor模板上:
on the following Razor template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
@(new System.Web.HtmlString(Model.EmailContent))
</body>
</html>
输出的电子邮件是HTM1编码的,但是我需要对其进行解码.我该怎么做?
the email that is outputted is HTMl encoded, but I need it decoded. How can I accomplish this?
推荐答案
与MVC的Razor View Engine一样,RazorEngine将自动对写入模板的值进行编码.为了解决这个问题,我们引入了一个名为 IEncodedString
的接口,默认实现为 HtmlEncodedString
和 RawString
.
RazorEngine, like MVC's Razor View Engine, will automatically encode values written to the template. To get around this, we've introduce an interface called IEncodedString
, with the default implementations being HtmlEncodedString
and RawString
.
要使用后者,只需调用 TemplateBase
的内置 Raw
方法:
To use the latter, simply make a call to the inbuilt Raw
method of TemplateBase
:
@Raw(Model.EmailContent)
这篇关于使用RazorEngine时如何输出原始html(不是来自MVC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!