0
在ASP MVC3 RedirectToAction杀死Session中的数据......为什么?ASP.MVC RedirectToAction杀死数据Session
请考虑这段代码。
[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");
}
如果我返回一个View而不是重定向到动作,Session仍然有我存储在那里的数据。
RedirectToAction非常重要,所以我将用户留在GET页面而不是POST页面上,以避免出现恼人的转发对话。
编辑:
这是我的控制器[SessionState的(SessionStateBehavior.ReadOnly)的顶部,当我删除它的行为正确。
你有没有试过使用'TempData'? –
如果我没有记错的话,使用它的好处是什么 – Peter
如果我没有记错,TemData仍然是基于会话的。 –