当我捕获一个 HttpPost 时,我正在重定向到另一个 ResultAction。它保留了我的 int 值,但不是我的列表值。似乎无法弄清楚为什么。如果我收到页码 = 2、searchAction = 3 和 clearResults(一个列表)的帖子,其中包含 25 个项目。它返回了我对帖子的期望,但是当我到达 Details ActionResult 时,它只保留 pageNumber 和 searchAction,而不是 clearResults 列表。奇怪的是,列表不是空的,它只是计数为 0。
模型:
public class ClearanceListViewModel
{
public ClearanceListViewModel()
{
this.pageNumber = 1;
this.searchAction = 1;
this.lastPage = false;
}
public ClearanceListViewModel(int pageNumber, int searchAction)
{
this.pageNumber = pageNumber;
this.searchAction = searchAction;
}
public int pageNumber { get; set; }
public int searchAction { get; set; }
public List<ClearanceViewModel> clearanceResults { get; set; }
public bool lastPage { get; set; }
}
在控制器中发布:
[HttpPost]
public ActionResult Details(ClearanceListViewModel model, FormCollection collection)
{
ClearanceListViewModel cModel = new ClearanceListViewModel();
cModel = model;
cModel.clearanceResults = model.clearanceResults;
// do something
return RedirectToAction("Details", cModel);
}
控制器中的操作结果:
public ActionResult Details(ClearanceListViewModel model)
{
DataTable dt = new DataTable();
List<ClearanceViewModel> clearanceList = new List<ClearanceViewModel>();
//save any changes
if (model.clearanceResults != null)
{
ClearanceSave(model);
model.clearanceResults = null;
}
string inQuery = "select sku, qty from products";
// call the query
dt = AS400DAL.Instance.ExecuteQueryAsDataTable(inQuery);
model = Utility.Utility.ProcessClearanceSkus(dt, model);
return View("Index",model);
}
任何输入将不胜感激。
谢谢!