當我捕捉到HttpPost時,我正在重定向到另一個ResultAction。它保留我的int值,但不是我的列表值。似乎無法弄清楚爲什麼。如果我得到頁碼爲2的帖子,searchAction = 3並且帶有25個項目的clearanceResults(一個列表)。它回來了我期望的帖子,但是當我到達Details ActionResult時,它只保留pageNumber和searchAction,而不是clearanceResults的列表。奇怪的事情,該列表不爲空,它只是具有計數0使用RedirectToAction時,它不保留我的模型
型號:
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);
}
任何輸入,將不勝感激。
謝謝!
一切都很好,直到您在網站上發佈,然後輪子脫落。 – spender
@spender是否發佈到網絡農場? – CR41G14
如果沒有,那麼這是沒有問題的,但我確實認爲在web服務器中持久化狀態有一個難聞的氣味。 – spender