【问题标题】:Generate html in body with RazorEngine email template使用 RazorEngine 电子邮件模板在正文中生成 html
【发布时间】:2016-11-17 19:59:02
【问题描述】:

我正在使用RazorEngine 生成带有模板的电子邮件。

我遇到的问题是我无法在电子邮件正文中添加换行符。

var model = new EmailModel
        {
            Destination = "anon@gmail.com",
            Subject = "Some Subject",
            Body = "Hello <br> Break <br> it <br> up"
        };

var service = TemplateManager.RazorService;
var htmlBody = service.RunCompile("EmailTemplate.cshtml", model.GetType(), model);
await EmailService.SendEmail(model.Destination, model.Subject, htmlBody);

我尝试在我的模板中执行以下操作:

@Html.Raw(Model.Body)

但它仍然无法解码 html,有什么想法吗?

【问题讨论】:

  • htmlBody中的RunCompile方法返回什么样的HTML字符串?同时显示您的 EmailTemplate.cshtml 内容代码。

标签: asp.net-mvc razorengine


【解决方案1】:

您在正文中的&lt;br&gt; 标签不正确。

&lt;br&gt; 替换为&lt;br /&gt;

【讨论】:

    【解决方案2】:

    更新:

    已在此处找到解决方案:https://github.com/Antaris/RazorEngine/issues/34

    在这里:RazorEngine: cannot use Html.Raw

    使用@(new RawString("html string here")) 或@Raw("html string here") 而不是 @Html.Raw("html string here")。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 2010-10-27
      • 1970-01-01
      • 2016-10-08
      • 2019-06-11
      相关资源
      最近更新 更多