當代碼跳轉到CreateProduct()時,填充的catList始終爲Count = 0,因此我認爲它不會傳遞。 考慮RouteValueDictionary不這樣做?任何其他方式?MVC RedirectToAction()以任何方式將對象傳遞給目標操作?
public ActionResult GetCats(int CatID)
{
List<Category> catList = new List<Category>();
if (CatID >= 0)
{
catList = context.Categories.Where(x => x.PCATID == CatID).ToList();
}
return RedirectToAction("CreateProduct", "Admin", new { catList });
}
public ActionResult CreateProduct(List<Category> catList) { }
我同意返回視圖或部分視圖,而不是重定向到操作。渲染操作並在過度使用時重定向到操作可能會影響應用程序的性能。 –