How can I generate html in action from a partial view?

I have an action. I want to send mail. I usually do that.

public ActionResult Action(Model model) { string body = "<html>"+ "<head>"+ "</head>"+ "<body>"+ "</body>"+ "</html>" MailMessage Message = new MailMessage(); Message.IsBodyHtml = true; Message.Subject = "some subject"; Message.Body = body; Message.To.Add(new MailAddress(adres)); Message.BodyEncoding = Encoding.GetEncoding("utf-8"); SmtpClient Smtp = new SmtpClient(); Smtp.EnableSsl = false; Smtp.Send(Message); return RedirectToAction("SomeAction","Controller"); } 

Can anyone say how I can generate HTML from PartialView and send this html email address?

something like that

 public ActionResult Action(Model model) { string str = GetHtmlFromPartialView("NamePartialView",model); MailMessage Message = new MailMessage(); Message.IsBodyHtml = true; Message.Subject = "some subject"; Message.Body = str; Message.To.Add(new MailAddress(adres)); Message.BodyEncoding = Encoding.GetEncoding("utf-8"); SmtpClient Smtp = new SmtpClient(); Smtp.EnableSsl = false; Smtp.Send(Message); return View(); } 
+1
asp.net-mvc asp.net-mvc-3
Dec 12 2018-11-12T00:
source share
2 answers
+1
Dec 12 '11 at 3:26 a.m.
source share

Checkout MvcMailer . Scott Hanselman also has a blog post about this. You will see how much easier and more fun it is to send emails. Mail templates are defined as Razor views.

+2
Dec 12 '11 at 3:26 a.m.
source share



All Articles