我怎么可以生成从局部视图操作HTML吗? [英] How can i generate html in action from partial view?
本文介绍了我怎么可以生成从局部视图操作HTML吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些动作。我想发送邮件。通常我这样做的方式。
公众的ActionResult行动(型号模型)
{
绳体=
< HTML和GT;+
< HEAD>中+
< /头>中+
<身体GT;+
< /身体GT;+
< / HTML>中 消息MAILMESSAGE新= MAILMESSAGE();
Message.IsBodyHtml = TRUE;
Message.Subject =一些主题;
Message.Body =身体;
Message.To.Add(新MailAddress(ADRES));
Message.BodyEncoding = Encoding.GetEncoding(UTF-8);
SmtpClient的smtp =新SmtpClient();
Smtp.EnableSsl = FALSE;
Smtp.Send(消息); 返回RedirectToAction(SomeAction,控制器);
}
任何可以说我怎么能生成HTML PartialView和发送这个网站低谷电子邮件?
像这样
公众的ActionResult行动(型号模型)
{
字符串str = GetHtmlFromPartialView(NamePartialView模型);
消息MAILMESSAGE新= MAILMESSAGE();
Message.IsBodyHtml = TRUE;
Message.Subject =一些主题;
Message.Body =海峡;
Message.To.Add(新MailAddress(ADRES));
Message.BodyEncoding = Encoding.GetEncoding(UTF-8);
SmtpClient的smtp =新SmtpClient();
Smtp.EnableSsl = FALSE;
Smtp.Send(消息); 返回查看();
}
解决方案
使用的<一个href=\"http://www.hanselman.com/blog/NuGetPackageOfTheWeek2MvcMailerSendsMailsWithASPNETMVCRazorViewsAndScaffolding.aspx\"相对=nofollow> MvcMailer包。
I have some action. I want send mail. usually i doing this way.
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 any say how can i generate HTML from PartialView and send this html trough email?
something like this
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();
}
解决方案
Use the MvcMailer package.
这篇关于我怎么可以生成从局部视图操作HTML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文