我正在尝试将我的对象集合放入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"];
它是null。我该如何投这个?
答案 0 :(得分:4)
而不是
TempData["model"] = model.Where(m => m.DeleteRow == true);
使用
TempData["model"] = model.Where(m => m.DeleteRow == true).ToList();
否则,您将存储IEnumerable&lt;&gt;的定义,而不存储任何数据。