Email screen in ASP.Net/MVC

I have an application consisting of 10+ related ascx files that we use to display our data in a users browser using the Html.RenderPartial helper.

I need to email data that are duplicates of what is on the screen. I would like to be able to get the generated html without having to take a screenshot.

Are there any suggestions on how to do this? I just try not to duplicate the work.

+1
source share
2 answers

http://www.brightmix.com/blog/renderpartial-to-string-in-asp-net-mvc/ has a good solution for rendering a view to a string so that you can send it by 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(); } 
+3
source

In regular asp.net, you can override Render () and provide your own HtmlWriter to intercept the displayed html before copying it to the HtmlWriter that was passed.

I don’t know how you would capture this in MVC, but I’m sure that you can do it, especially if you create a new HttpModule as a preprocessor, post processes the output stream.

+3
source

All Articles