值不能为空。参数名称实体

时间:2019-01-07 18:12:43

标签: c# asp.net ajax asp.net-ajax

我想使用Ajax删除。当我按Delete键时,发生异常: Value cannot be null. Parameter name entity.

控制器代码如下:

public ActionResult DeleteCar(int? Id)
{
    var cardetail = car.Cars.Find(Id);
    return View(cardetail);
}

public ActionResult DeleteConfirmed(int? Carid)
{
    Car cardetail = car.Cars.Find(Carid);
    car.Cars.Remove(cardetail);
    car.SaveChanges();
    return Content("Success");
}

删除的Ajax代码如下。

$(document).on('click', '.deleteStd', function () {
    //  alert();
    var Carid = $(this).attr('id');
    $.ajax({
        type: "post",
        url: "/Home/DeleteConfirmed?Carid=" + Carid,
        ajaxasync: true,
        success: function () {
            alert("Record delete successfully");
            location.reload();
        },
        error: function (data) {
            alert(data.x);
        }
    });
});

0 个答案:

没有答案