Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net MVC邮件程序将模型传递到邮件视图_Asp.net_Asp.net Mvc_Asp.net Mvc 3_Mvcmailer - Fatal编程技术网

Asp.net MVC邮件程序将模型传递到邮件视图

Asp.net MVC邮件程序将模型传递到邮件视图,asp.net,asp.net-mvc,asp.net-mvc-3,mvcmailer,Asp.net,Asp.net Mvc,Asp.net Mvc 3,Mvcmailer,我正在使用MVC邮件器-我的控制器中有: // // POST: /ExhibitorInterest/Create [HttpPost] public ActionResult Create(ExhibitorInterest exhibitorinterest) { if (ModelState.IsValid) { db.ExhibitorInterests.Add(exhibitorinte

我正在使用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);
    }
但我想将模型参展商兴趣传递给mailer视图:

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");
        });
    }
你知道我是如何将exhibitorinterest添加到UserMailer.cs的吗?这样我就可以将它添加到邮件视图了

谢谢,


Mark

我想我找到了答案-将IUSerMailer.cs的签名更改为:

public interface IUserMailer
{
 MvcMailMessage ExhibitorInterest(ExhibitorInterest exhibitorinterest); 
和UserMail.cs发送至:

public virtual MvcMailMessage ExhibitorInterest(ExhibitorInterest exhibitorinterest)
{
 ViewBag.Data = exhibitorinterest.xxxxxxx;
希望它能帮助别人


谢谢,Mark

我想我知道了-将IUSerMailer.cs的签名更改为:

public interface IUserMailer
{
 MvcMailMessage ExhibitorInterest(ExhibitorInterest exhibitorinterest); 
和UserMail.cs发送至:

public virtual MvcMailMessage ExhibitorInterest(ExhibitorInterest exhibitorinterest)
{
 ViewBag.Data = exhibitorinterest.xxxxxxx;
希望它能帮助别人


谢谢,Mark

我确实发布了类似的内容,但对GitHub中显示的基本示例感到困惑,并尝试使用最佳实践,因此如果这看起来像是一个转载,我表示歉意-我现在有3个邮件视图-其中一个在上面,因此对我来说越来越复杂,需要弄清楚并保持干净。谢谢。我确实发布了一些类似的东西——但对GitHub中显示的基本示例感到困惑——并尝试使用最佳实践——因此,如果这看起来像是一个转发,我表示歉意——我现在有3个邮件视图——其中一个在上面,因此对我来说越来越复杂,并且保持干净。非常感谢。