我正在使用放置在MasterPage中的LoginBox,以便用户能够从任何网站页面登录。
表单操作由
声明<% using (Html.BeginForm("LogOn", "Account", FormMethod.Post))
但在POST之后如果登录失败,我需要留在同一页面上并显示验证消息。
那么我怎样才能留在调用页面而不是被重定向到Account LogOn View?
感谢。
答案 0 :(得分:0)
您可以在登录表单中附加returnurl字段:
using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { @returnurl=Request.Uri.AbsolutePath }))
并在您的Account.LogOn操作中重定向回来
ActionResult LogOn(Form form) { ... check login/password ... return Redirect(form["returnurl"])}
答案 1 :(得分:0)
因此帖子将转到您的帐户控制器,LogOn操作。我建议您调用“身份验证”操作......
<% using (Html.BeginForm("Authenticate", "Account", FormMethod.Post))
这样,您的操作就会执行身份验证,失败的身份验证会返回View(),并且成功会将您带到LoggedIn视图。