(Jquery Ajax Call )Post 一个Form去后台以及AJAX call后DIV重新加载

来源:互联网 发布:怎么样做淘宝网店 编辑:程序博客网 时间:2024/05/14 21:06
<form action="/Customer/LoginPartial" id="signinform1" method="post">                <div class="span5">
  

</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 }); 
            }
            
        }

原创粉丝点击