How to Email Screen in ASP.Net/MVC

前端 未结 2 1959
耶瑟儿~
耶瑟儿~ 2020-12-10 23:48

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.

I need to e

相关标签:
2条回答
  • 2020-12-11 00:03

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

    I don't know off the top of my head how you'd intercept this in MVC, but I'm sure you'll be able to do it - especially if you make a new HttpModule in the pipeline to pre-post process the output stream.

    0 讨论(0)
  • 2020-12-11 00:13

    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();
    }
    
    0 讨论(0)
提交回复
热议问题