In ASP MVC3 RedirectToAction kills data in Session…WHY?
Consider this code.
[HttpGet]
public ActionResult RequestTestExtract()
{
return View(new ExtractRequestViewModel());
}
[HttpPost]
public ActionResult RequestTestExtract(ExtractRequestViewModel viewModel)
{
var currentExtracts = (Session["Extracts"] as Dictionary<string, bool>) ?? new Dictionary<string, bool>();
currentExtracts.Add(viewModel.fileName, false);
Session["Extracts"] = currentExtracts;
// typing
// ?Session["Extracts"]
// in immediate window before RedirectToAction shows a value
// typing it after does not
return RedirectToAction("RequestTestExtract");
}
If I return a View instead of redirect to action the Session still has the data I stored there.
The RedirectToAction is important so I leave the user on a GET page rather than a POST page to avoid that annoying repost dialogue that comes up.
EDIT:
This was at the top of my controller [SessionState(SessionStateBehavior.ReadOnly)] when I delete this it behaves properly.
This was at the top of my controller [SessionState(SessionStateBehavior.ReadOnly)] when I delete this it behaves properly.