</form>
$("#signinbtn1").click(function () {
$.ajax({
url: "/Customer/LoginPartial",
type: "POST",
dataType: "json",
data: $("#signinform1").serialize(),
error: function (xhr) {
},
success: function (json) {
json = json || {};
if (json.success) {
$("#headerlinkdiv").load("/Common/HeaderLinks"); //DIV重新加载
$(".modal-backdrop").remove();
//window.location = json.redirect || location.href;
} else if (json.errors) {
displayErrors($("#signinform1"), json.errors);
}
}
});
});
<div id="headerlinkdiv">@Html.Action("HeaderLinks", "Common")</div>
public JsonResult LoginPartial(LoginModel model, string returnUrl)
{
var errors = new { errors = ModelState.SelectMany(x => x.Value.Errors.Select(error => error.ErrorMessage)) };
if (errors.errors.Count() > 0)
{
return Json(errors);
}
else
{
return Json(new { success = true, redirect = returnUrl });
}
}