我正在使用MVC邮件程序 - 我在我的控制器中有这个:
//
// POST: /ExhibitorInterest/Create
[HttpPost]
public ActionResult Create(ExhibitorInterest exhibitorinterest)
{
if (ModelState.IsValid)
{
db.ExhibitorInterests.Add(exhibitorinterest);
db.SaveChanges();
UserMailer.ExhibitorInterest().Send();
return RedirectToAction("Thankyou");
}
return View(exhibitorinterest);
}
但我想将模型 Exhibitorinterest 传递给邮件程序视图:
UserMailer.cs有:
public virtual MvcMailMessage ExhibitorInterest()
{
//ViewBag.Data = someObject;
return Populate(x =>
{
x.Subject = "ExhibitorInterest";
x.ViewName = "ExhibitorInterest";
x.To.Add("me@myemail.co.uk");
});
}
我是如何将参展商的兴趣转化为UserMailer.cs的 - 所以我可以将它添加到邮件视图中吗?
谢谢,
标记
答案 0 :(得分:3)
想想我想出来了 - 将IUSerMailer.cs的签名更改为:
public interface IUserMailer
{
MvcMailMessage ExhibitorInterest(ExhibitorInterest exhibitorinterest);
和UserMail.cs:
public virtual MvcMailMessage ExhibitorInterest(ExhibitorInterest exhibitorinterest)
{
ViewBag.Data = exhibitorinterest.xxxxxxx;
希望它可以帮助别人。
谢谢,Mark