[英]C# MVC ActionLink clear session before reloading page
我有一个简单的表单页面,用户可以在其中填写一些数据。 在我按下post之后,我需要所有这些数据保持原样,因此,如果用户想要更改数据,他/她可以。 保存数据后,我将Client
对象存储在Session
,每按一次Save按钮,都会检查Session
是否已有用户。
现在我有了@Html.ActionLink("New client", "NewUser");
,当我想创建新用户时按。 因此,此链接将重新加载页面并清除Session
。
请注意, "New user"
应该重定向到Index
,但是我设法使其像这样工作,但这不是有效的方法。
控制器代码:
public ActionResult Index()
{
return View(_vm);
}
public ActionResult NewUser()
{
Session["newClient"] = null;
return RedirectToAction("Index");
}
清除session
只能在后端完成,因此您必须采取措施清除会话,但不需要return RedirectToAction("Index");
而是返回视图
public ActionResult NewUser()
{
Session["newClient"] = null;
return View("Index",_vm);
}
因为您将redirecting
到index
视图以创建新用户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.