我一直在互联网上试图弄清楚这一点。我正在尝试添加一个 jquery 对话窗口,该窗口将调用一个操作来登录用户,然后在成功登录后将用户重定向到他们的个人资料页面,否则保持对话窗口打开并用适当的错误消息提示用户。到目前为止,登录部分似乎可以工作,但是当操作返回时,它会使用户保持在同一页面上。我需要进行哪些更改才能确定成功登录并正确重定向?这是我的代码:
"Javascript code"
$.validator.unobtrusive.parse('#LogOnForm');
$('#LogOnDialog').dialog({
autoOpen: false, width: 450, height: 300, modal: true,
buttons: {
'Log On': function () {
if ($('#LogOnForm').validate().form()){
$.ajax({
url: '@Url.Action("LogOnPartial", "Account")',
type: 'POST',
data: $('form').serialize(),
datatype: 'json',
success: function (result) {
$('#LogOnDialog').html(result).dialog('open');
}
});
}
},
Cancel: function () {
$(this).dialog('close');
}
}
});
$('#linkSignIn').live('click', function () {
$('#LogOnDialog').html('')
.dialog('option', 'title', 'Sign In')
.load('@Url.Action("LogOnPartial", "Account")', function () { $('#LogOnDialog').dialog('open'); });
});
"Controller Action"
[HttpPost]
public ActionResult LogOnPartial(LogOnModel model)
{
if (ModelState.IsValid)
{
UserPrincipal principal = new UserPrincipal(model.EmailAddress, model.Password);
HttpContext.User = principal;
FormsAuthentication.SetAuthCookie(model.EmailAddress, true);
return PartialView("LogOnPartial", model);
}
return PartialView("LogOnPartial", model);
}