从TempData(MVC C#)投射对象的集合

本文关键字:对象 集合 TempData MVC | 更新日期: 2023-09-27 18:21:09

我正试图将我的对象集合放入TempData中,如下所示:

  [HttpPost]
  public ActionResult PandoraRemovalTotal2(List<Business.Models.Administration.CorrespondenceRecordViewModel> model, string hdnMem)
    {
        Business.Administration.Pandora Pandora = new Business.Administration.Pandora();
        model = Pandora.DeleteDocs(model);
        TempData["model"] = model.Where(m => m.DeleteRow == true);
        return RedirectToAction("PandoraDocsDeleted", new {memNum = hdnMem });
    }

并通过重定向传递到操作

[HttpGet]
public ActionResult PandoraDocsDeleted(string memNum)
{
    var model = (List<Business.Models.Administration.CorrespondenceRecordViewModel>)TempData["model"];
    ViewBag.MemNum = memNum;
    return View(model);
 }

但当我这样做时:

var model = (List<Business.Models.Administration.CorrespondenceRecordViewModel>)TempData["model"];

它为空。我该如何铸造?

从TempData(MVC C#)投射对象的集合

而不是

TempData["model"] = model.Where(m => m.DeleteRow == true);

使用

TempData["model"] = model.Where(m => m.DeleteRow == true).ToList();

否则,您正在存储IEnumerable<>的定义,没有任何数据。