如何使用Razor从适合电子邮件的视图创建HTML字符串? [英] How do I use Razor to create an HTML string from a view suitable for email?

查看:117
本文介绍了如何使用Razor从适合电子邮件的视图创建HTML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我发现的答案似乎表明System.Web ....命名空间中的任何内容,你无法访问任何必要的说这是一个视图和模型,给我HTML。 br />


相反,人们指向RazorEngine或MvcMailer。



真的吗?没有去第三方实用程序我无法访问解析引擎???我觉得很难相信。

解决方案

你好,



我认为这是可能的......



创建一个新的局部视图和匹配的新布局。



在局部视图中使用布局

 @ model Myapp.EmailModel 
@ {
Layout =〜/ Views / Shared / Email_layout.cshtml
}





在layoiut中,渲染局部视图...



< pre lang =HTML> < html >
< head > ;
< meta 名称 = viewport <温泉n class =code-attribute> content = width = device-width / >
< title > 电子邮件< / title >
< / head >
< body >
@RenderBody()
< / body >
< / html >





现在你可以在@ Html.Partial的任何地方使用它。



 @ Html.Partial(EmaillView,emailModel )







Valery。


The answers I've found so far seem to indicate that whatever is in the System.Web.... namespaces, you cannot access whatever is necessary to say "here's a view and model, give me the HTML."

Instead, people point to RazorEngine or MvcMailer.

Really? I can't access the parsing engine without going to some third party utility??? I find that hard to believe.

解决方案

Hello,

I think it is possible...

Create a new partial view and a matching new layout.

In the partial view use the layout

@model Myapp.EmailModel
@{
  Layout="~/Views/Shared/Email_layout.cshtml"
}



in the layoiut, render the partial view...

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Email</title>
</head>
<body>
        @RenderBody()        
</body>
</html>



now you can use this with @Html.Partial anywhere you like..

@Html.Partial("EmaillView", emailModel)




Valery.


这篇关于如何使用Razor从适合电子邮件的视图创建HTML字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆