本文介绍了发送电子邮件并同时将(模型数据)电子邮件ID保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 public PartialViewResult Sub1(SuperVM picvm) { picvm = new SuperVM() { SubsCribe = new SubsCribe() { SubscribeEmail = picvm.SubsCribe.SubscribeEmail, Subject =picvm.SubsCribe.Subject } }; SmtpClient smtp = new SmtpClient("mail.ABC.com"); if(ModelState.IsValid) { MailMessage mail = new MailMessage(); mail.To.Add(new MailAddress("[email protected]")); mail.Bcc.Add(new MailAddress(picvm.SubsCribe.SubscribeEmail)); mail.From = new MailAddress("[email protected]"); mail.Subject = picvm.SubsCribe.SubscribeEmail + " ****-----Subscribed------****** "; mail.Body = string.Format(mail.Subject); mail.IsBodyHtml = true; smtp.Port = 25; smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential("[email protected]", 1234567 "); smtp.EnableSsl = false; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Send(mail); db.SubsCribes.Add(picvm.SubsCribe); db.SaveChanges(); return PartialView("Sub1",picvm); } else { return PartialView(); } } 我尝试过: 我正在尝试发送电子邮件 - 其中工作, 但是我试图将电子邮件ID(模型属性 - What I have tried:I am trying to Send Email - which is working,But along I am trying to save email Id(Model property - SubscribeEmail )保存到数据库。 因此,除了以上邮件之外,我还添加以下内容: ) to database. So along with above mailing stuff I am adding this lines : db.SubsCribes.Add(picvm.SubsCribe); db.SaveChanges(); 电子邮件发送成功,但是,电子邮件ID未保存到数据库。 请帮助。 谢谢提前。Email is sending successfully, but, email id is not saving to database.Please Help.Thanks in Advance.推荐答案 picvm.SubsCribe.SubscribeEmail = [email protected] 但是如果你要向partialview方法发送数据那么请解释你为什么使用下面的代码? picvm =新SuperVM() { SubsCribe =新的SubsCribe() { SubscribeEmail = picvm.SubsCribe.SubscribeEmail, Subject = picvm.SubsCribe.Subject } }; but if you are sending data to the partialview method then please explain why are you using below code? picvm = new SuperVM() { SubsCribe = new SubsCribe() { SubscribeEmail = picvm.SubsCribe.SubscribeEmail, Subject =picvm.SubsCribe.Subject } }; 这篇关于发送电子邮件并同时将(模型数据)电子邮件ID保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 14:19