堆栈不足以继续以模态安全地执行程序

时间:2016-03-29 20:45:09

标签: asp.net asp.net-mvc twitter-bootstrap bootstrap-modal

当我以模态形式输入错误的密码或电子邮件以登录我的MVC网站时,我的viewbag在我的控制器代码中不起作用:

    public ActionResult Login()
    {
        return PartialView();
    }
    [HttpPost]
    public  ActionResult Login(LoginViewModel login)
    {
        if (ModelState.IsValid)
        {
            var Encode = Encryption.EncodePasswordMd5(login.Password);
            var logined = db.Members.Where(s => s.EmailAddress == login.EmailAddress && s.Password == Encode).FirstOrDefault();
            if (logined != null)
            {     //todo: redircet to admin panel
                if (logined.Role==Role.admin)
                {
                    FormsAuthentication.SetAuthCookie(logined.Id.ToString(), login.KeepMe);
                    return RedirectToAction("panel", "Admin");
                }
                  //todo: redircet to user panel
                    FormsAuthentication.SetAuthCookie(logined.Id.ToString(), login.KeepMe);
                    return RedirectToAction("Index", "Home");
            }
            ViewBag.Error = "wrong email or password";
            return View();
        }

        return View(login);
    } 

这是我的布局中的引导模式:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        </div>
        <div class="modal-body" id="bodymodal">
            @Html.Action("Login","Account")
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

登录操作方法返回一个包含Login操作方法的视图。基本上,你一遍又一遍地称呼自己。

您可能只需要包含不同的Action方法:@Html.Action("LoginForm","Account")