读书人

懂MVC3的入

发布时间: 2013-11-09 17:06:41 作者: rapoo

懂MVC3的进!
想做这种效果!
当用户从新登陆 或者因为cookie过期了 从新登陆后需要回到原来的页面
但目前的代码是 当登陆过程中有过错误(密码或者用户名错误再次点击登陆) 就返回不到原来的页面了 。
View:Logon.cshtml


@using (Html.BeginForm("LogOn", "Account", new { Request.ServerVariables["http_referer"] }, FormMethod.Post))
{...

Controller中的Logon Action:

[HttpPost]
public ActionResult Logon(LogonInfo model, string returnUrl)
{
string[] loginResult;

if (!string.IsNullOrEmpty(model.UserID) && !string.IsNullOrEmpty(model.Password))
{
// 验证登陆
if (this.TryLogin(model.UserID, model.Password, out loginResult))
{
//model.UserName = string.Empty;
//Response.Cookies.Remove(model.UserID);
Response.Cookies.Remove(model.UserID);
...
//其他操作.....
// 记住登陆状态
FormsAuthentication.SetAuthCookie(model.UserID, model.RememberMe);

if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
}
return View(model);
}

想要 让它登陆过程中 出现错误不刷新页面 怎么做? if (ModelState.IsValid)貌似也刷新页面?
[解决办法]
想要 让它登陆过程中 出现错误不刷新页面 怎么做?

js check或者ajax
[解决办法]
用ajax来调用action。

http://blog.csdn.net/sqqyq/article/details/7331591
可以看看上面链接的 JS(AppView.js)中的ajax部分。

读书人网 >C#

热点推荐