I'm developing an ASP.NET MVC application that will send the user a confirmation email. For the email itself, I'd like to create a view and then render that view and send it using the .NET mail objects.
How can I do this using the MVC framework?
asp.net-mvcframeworksrenderview
I'm developing an ASP.NET MVC application that will send the user a confirmation email. For the email itself, I'd like to create a view and then render that view and send it using the .NET mail objects.
How can I do this using the MVC framework?
Best Answer
You basically need to use
IView.Render
. You can get the view by usingViewEngineCollection.FindView
(ViewEngines.Engines.FindView
for the defaults). Render the output to aTextWriter
and make sure you callViewEngine.ReleaseView
afterwards. Sample code below (untested):I'll leave viewData / tempData to you.