I use a simple sequences:
- Set a Session State in [HttpGet] method.
- Redirect to another action using RedirectToAction() in [HttpPost] method.
- Want to get the value of that Session State, in the destination.
Problem:
If user hits "submit" button on my "Table" view, all the data inside session got cleared and I can't get them in the destination action (which is "Table"). Here is the code:
[HttpGet]
public ActionResult Edit(string TableName, int RowID, NavigationControl nav)
{
if (nav != null) Session["NavigationData"] = nav;
myService svc = new myService (_repository);
EditViewModel model = new EditViewModel();
model.TableDefinitions = svc.GetTableDefinition(TableName);
model.RowData = svc.GetRowData(model.TableDefinitions.Name, RowID);
return View(model);
}
[HttpPost]
public ActionResult Edit(EditViewModel model)
{
MyService svc = new MyService (_repository);
svc.SaveRowData(model.TableDefinitions.Name, model.RowData);
return RedirectToAction("Table");
}
public ActionResult Table(string TableName)
{
myService svc = new myService (_repository);
TableViewModel model = new TableViewModel();
model.TableDefinition = svc.GetTableDefinition(TableName);
NavigationControl nav = (NavigationControl)Session["NavigationData"];
if (nav != null)
{
model.NavigationControl = nav;
}
return View(model);
}
and Session["NavigationData"] is always null when user reaches it via: return RedirectToAction("Table"). If user hits an HTML link on "Edit" View, Session["NavigationData"] can restore its value in "Table" method!
Any idea about what's going on? Who deletes the Session state?!