【问题标题】:Render Html code from a property using FluentMail in C#在 C# 中使用 FluentMail 从属性渲染 Html 代码
【发布时间】:2020-05-05 03:32:54
【问题描述】:

我正在使用 FluentMail 从 .Net Core 中的模板发送电子邮件。 使用的时候有个问题,因为一个属性是我存储HTML的字符串,问题是不是处理HTML,而是像打印一样

<p> this is a text </p> 

而不是

this is a text

代码基本上是这样的:

var inviteEmailViewModel = new InviteEmailViewModel(_emailAppSettings.EmailInviteSubject,
               requester.Name,
               roleName,
               entityType,
               entityName,
               invitationUrl,
               registrationUrl,
               textPreview,
               text);

            var inviteEmailPath = $"{Directory.GetCurrentDirectory()}{_emailAppSettings.EmailInvitePath}";

            List<Address> adresses = emailsTo.Select(x => new Address() { EmailAddress = x }).ToList();

            var sendResponse = await _fluentEmail
               .To(adresses)
               .Subject(_emailAppSettings.EmailInviteSubject)
               .UsingTemplateFromFile(inviteEmailPath, inviteEmailViewModel)
               .SendAsync();

InviteEmailViewModel 具有string 属性Text

模板定义如下

<table>
    <tbody>
        <tr>
            <td>@Model.Text</td> 
        </tr>
    </tbody>
</table>

如何渲染传递给字符串的 HTML,而不是将其打印为字符串?

我已经尝试过类似@Html.Raw 的方法,但它会在 FluentMail 上引发异常。

【问题讨论】:

    标签: c# asp.net .net email .net-core


    【解决方案1】:

    我找到了这个解决方案:https://stackoverflow.com/a/23603594/8391028

    <table>
    <tbody>
        <tr>
            <td>@Raw(Model.Text)</td> 
        </tr>
    </tbody>
    

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 1970-01-01
      • 1970-01-01
      • 2020-05-04
      • 2017-04-16
      • 2015-02-11
      • 1970-01-01
      • 2014-06-22
      相关资源
      最近更新 更多