我有一个简单的表单页面,用户可以在其中填写一些数据。按下 post 后,我需要所有数据保持原样,因此如果用户想要更改数据,他/她可以。保存数据后,我将Client
对象存储在其中Session
,每次按“保存”按钮时,我都会检查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
视图
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句