JQUERY没有关闭弹出和刷新页面

时间:2016-03-23 07:15:41

标签: jquery asp.net-mvc

我正在使用以下脚本并成功从数据库中删除基础记录。但点击确认后,根本没有任何事情发生。意思是我必须关闭两个弹出窗口然后在浏览器上点击F5才能看到结果。我尝试了很多东西,但必须是我在这里缺少的简单的东西

function deletePayment(customerPaymentId) {
    //alert(customerPaymentId);
    bootbox.confirm("Are you sure? This payment will be logically deleted", function (result) {
        if (result) {
            var url = '/CustomerPayment/Delete';
            var data = {
                id: customerPaymentId
            };

            $.post(url, data, function () {

                window.location.reload();
            });



        }
    });
    return false;
}

以下控制器代码:

//[HttpPost, ActionName("Delete")]
//[ValidateAntiForgeryToken]

//[Authorize(Roles = "Delete")]
public ActionResult Delete(int id)
{

    CustomerPayment obj = _db.GetCustomerPayment(id);

    _db.Edit(obj);

    obj.TransactionDateTimeEnd = DateTime.Now;
    _db.Save();




    return View("Index", new { id = obj.CustomerId});
}

2 个答案:

答案 0 :(得分:0)

这是我测试的正确代码。

我会告诉你删除return false并使下面的ajax调用显式附加成功和失败回调。

$(document).on("click", ".alert", function (e) {
            bootbox.confirm("Delete payment ???", function (result) {
                    if (result) {
                        alert('delete fired');
                        $.ajax({
                            type: "GET",
                            url: "Jquery-datatable.aspx/GetJsonEmps",
                            data: "{}",
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            success: function (response) {
                                alert('ok');
                                location.reload();
                            },
                            error: function (xhr, ajaxOptions, thrownError)
                            { 
                            alert(xhr.responseText);
                            location.reload(); 
                            }    
                        });
                    }
                });
            });

注意:为了测试,我已经快速检查了上面的示例。您必须将rquest类型替换为POST并请求url并添加data参数。

答案 1 :(得分:0)

对于控制器

public JsonResult Delete(int? id)
        {           
            if (isSuccess)
                return Json(new { Success = true, Message = "" }, JsonRequestBehavior.AllowGet);
            else
                return Json(new { Success = false, Message = error }, JsonRequestBehavior.AllowGet);
        }

并在脚下添加

window.location.href = window.location.href;

如果您有任何疑问,请与我联系。

相关问题