How can I delete data from my database in ASP.NET MVC without reloading the page ?
I tried all the methods but couldn't find a solution.
This is my ajax code :
(".remove-hasan").on("click", function () {
var id = $(this).attr("data-id");
$.ajax({
url: "/Main/DeleteFavourite" + id,
type: "POST",
data: { id: id, },
success: function (response) {
if (response == "ok") {
$(".modal-action-messages").empty();
$(".modal-action-messages").append("Ürün Başarıyla Favorilerinizden Çıkarılmıştır.");
$this.find(".remove").removeClass(".remove");
$this.find(".remove").addClass(".remove");
}
}
});
});
Controller :
[HttpPost]
public IActionResult DeleteFavourite(int id)
{
var product = _uow.Favourite.GetAll()
.Where(p => p.ProductId == id)
.FirstOrDefault();
_uow.Favourite.Delete(product);
return Json("ok");
}