HTML PAGE
function Delete(CategoryId) { swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, confirmButtonClass: "btn-danger", confirmButtonText: "Yes, delete it!", cancelButtonText: "No, cancel plx!", closeOnConfirm: false, closeOnCancel: false }, function(isConfirm) { if (isConfirm) { swal("Deleted!", "Your record has been deleted.", "success"); $.get("/Home/Delete", { CategoryId: CategoryId }, function (res) { if (res) { dataTable.ajax.reload(); } }) } else { swal("Cancelled", "Your imaginary file is safe :)", "error"); } });
Home Controller
public ActionResult Delete(int CategoryId) { try { ASPNETMASTERPOSTEntities db = new ASPNETMASTERPOSTEntities(); var categories = db.tblCategories.Find(CategoryId); db.tblCategories.Remove(categories); db.SaveChanges(); return Json(true, JsonRequestBehavior.AllowGet); } catch (Exception) { return Json(false, JsonRequestBehavior.AllowGet); }
}