我想使用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);
}
});
});