如何电子邮件画面中ASP.Net/MVC [英] How to Email Screen in ASP.Net/MVC

查看:170
本文介绍了如何电子邮件画面中ASP.Net/MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是由我们用来显示关于使用Html.RenderPartial帮助用户的浏览器我们的数据10+相关ASCX文件的应用程序。

I have an application that is made up of 10+ related ascx files that we use to display our data on the users browser using the Html.RenderPartial helper.

我要电子邮件是什么在屏幕上重复的数据。我希望能够得到生成的HTML而不必做一个屏幕抓取。

I need to email the data that is a duplicate of what is on screen. I would like to be able to get the generated html without having to do a screen scrape.

是否有任何建议,如何做到这一点?我只是试图从重复的工作保持。

Are there any suggestions as to how to do this? I'm just trying to keep from duplicating the work.

推荐答案

http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/ 有渲染视图为字符串,所以你可以发送一个很好的解决方案它在电子邮件。

http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/ has a good solution for rendering a View to a string so you can send it in email.

/// Static Method to render string - put somewhere of your choosing
public static string RenderPartialToString(string controlName, object viewData)
{
     ViewDataDictionary vd = new ViewDataDictionary(viewData);
     ViewPage vp = new ViewPage { ViewData = vd };
     Control control = vp.LoadControl(controlName);

     vp.Controls.Add(control);

     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (HtmlTextWriter tw = new HtmlTextWriter(sw))
         {
             vp.RenderControl(tw);
         }
     }

     return sb.ToString();
}

这篇关于如何电子邮件画面中ASP.Net/MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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