在Razor邮件模板中使用@ Html.Raw呈现HTML内容 [英] Rendering HTML content with @Html.Raw in Razor Mail Template
问题描述
使用Razor页面作为邮件模板我正在尝试使用@Html.Raw(Model.Content)
显示邮件的内容(HTML内容).
Using Razor page as Mail Template I am trying to display the content of the mail (Html Content) using @Html.Raw(Model.Content)
.
每次运行代码时,都会出现以下错误:html does not exist in current context
.
Anytime I run the code I get this error: html does not exist in current context
.
我在另一个剃须刀页面上尝试过此@Html.Raw("<strong>Bold!</strong>")
来验证RazorEngine
是否已安装,并且显示完美,没有错误.
I tried this @Html.Raw("<strong>Bold!</strong>")
on another razor page to validate RazorEngine
is installed and it displayed perfectly well with no error.
推荐答案
在发送电子邮件时,我在RazorEngine.Templating中使用RazorEngineService.就我而言,看起来像这样:
When doing e-mails, I use the RazorEngineService in RazorEngine.Templating, e.g. in my case, it looks like this:
using RazorEngine.Templating;
RazorEngineService.Create().RunCompile(html, ...)
假设您使用的是同一程序集,则@ Html.Raw在这种用法下不存在.我终于可以通过在电子邮件中执行以下操作来获取原始HTML输出:
Assuming you are using the same assembly, @Html.Raw does NOT exist with this usage. I was finally able to get raw HTML output by doing this in my e-mails:
@using RazorEngine.Text
@(new RawString(Model.Variable))
这篇关于在Razor邮件模板中使用@ Html.Raw呈现HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!