c# – 将模型从一个动作传递到同一个控制器中的另一个动作

前端之家收集整理的这篇文章主要介绍了c# – 将模型从一个动作传递到同一个控制器中的另一个动作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图通过我的模型列表< Models.Statement> statementList从一个动作到另一个动作,但我在第二个控制器中收到空值.请在这里建议有什么问题.甚至试过:
return RedirectToAction("WriteInTemplate",new { statementList = statementList });

请帮忙.

public ActionResult SendPdfStatement(string InvoiceNumber)
    {
        try
        {
            InvoiceNumber = InvoiceNumber.Trim();

            ObjectParameter[] parameters = new ObjectParameter[1];
            parameters[0] = new ObjectParameter("InvoiceNumber",InvoiceNumber);

            List<Models.Statement> statementList = new List<Models.Statement>();
            statementList = _db.ExecuteFunction<Models.Statement>("uspInvoiceStatement",parameters).ToList<Models.Statement>();

            //WriteInTemplate(statementList);
            return RedirectToAction("WriteInTemplate",statementList );

        }
        catch (Exception e)
        {
            InvoiceSearchTool.Models.udtExceptionTable exception = new udtExceptionTable();
            exception.MethodName = "SendPdfStatement";
            exception.Exception = e.ToString();
            exception.Date = DateTime.Now;
            DYNAMICS_EXTEntities db = new DYNAMICS_EXTEntities();
            db.AddToudtExceptionTables(exception);
            db.SaveChanges();  
            return View("Error");
        }
    }

    public ActionResult WriteInTemplate(List<Models.Statement> statementList)
    {
        try
        {
            string invoiceNumber = statementList.FirstOrDefault().Invoice.ToString().Trim();
        ...................snip..........


            return RedirectToAction("CreateMessageWithAttachment","email",invoiceNumber); 
        }
        catch (Exception e)
        {
            InvoiceSearchTool.Models.udtExceptionTable exception = new udtExceptionTable();
            exception.MethodName = "WriteInTemplate";
            exception.Exception = e.ToString();
            exception.Date = DateTime.Now;
            DYNAMICS_EXTEntities db = new DYNAMICS_EXTEntities();
            db.AddToudtExceptionTables(exception);
            db.SaveChanges();

            return View("Error");
        }

    }

解决方法

请看看 here to pass your Model

你没有传递“statementList”,而是传递新的{statementList = statementList}只是传递模型,你应该没问题.

return RedirectToAction("WriteInTemplate",statementList);

回答sino

原文链接:https://www.f2er.com/csharp/99687.html

猜你在找的C#相关文章