我需要根据选中的复选框向多个用户发送电子邮件。
在控制器中:
[HttpGet]
public ActionResult ChkBxSendMail(int[] check)
{
return View();
}
[HttpPost]
public ActionResult ChkBxSendMail(int[] check, Profile profile, mail email)
{
foreach (var item in check)
{
var dbprofile = db.Profile.Single(p => p.ProfileId == item);
string Emailid = dbprofile.EmailId;
//var mailid = from p in db.Profile where p.ProfileId == id select p.EmailId;
MailMessage msg = new MailMessage();
MailAddress fromAddress = new MailAddress("xxxx");
msg.From = fromAddress;
msg.To.Add(Emailid);
msg.Subject = email.Subject;
msg.Body = email.Body;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential("xxxxxx", "xxxx");
client.Send(msg);
}
return RedirectToAction("Profiles", "profile");
}
在视图中:
"input type="checkbox" name="check" value="<%: item.ProfileId %>" /> " 用于表..
问题
无法将复选框选择的值传递给操作结果。