
Delete button is working but if refresh index page then update data i want if delete then refresh that page
Edited
#region DeleteAPICALL
[HttpDelete]
public IActionResult Delete(int? id)
{
var product = _unitOfWork.Prodcut.GetT(x => x.Id == id);
if (product == null)
{
return Json(new { success = false, message = "Error in fetching Data" });
}
else
{
var oldImagePath = Path.Combine(_webHost.WebRootPath, product.ImageUrl.TrimStart('\\'));
if (System.IO.File.Exists(oldImagePath))
{
System.IO.File.Delete(oldImagePath);
}
_unitOfWork.Prodcut.Delete(product);
_unitOfWork.Save();
return Json(new { success = true, message = "Product Deleted..." });
}
}
#endregion
var dtable;
$(document).ready(function () {
dtable = $("#myTable").DataTable({
"ajax": {
"url": "/Admin/Product/AllProduct"
},
"columns": [
{ "data": "name" },
{ "data": "description" },
{ "data": "price" },
{ "data": "category.name" },
{
"data": "id",
"render": function (data) {
return `
<a href="/Admin/Product/CreateEdit?id=${data}"><i class="bi bi-pencil-square"></i></a>
<a onClick=RemoveProduct("/Admin/Product/Delete/${data}")><i class="bi bi-trash"></i></a>
`
}
}
]
});
});
#region DeleteAPICALL
[HttpDelete]
public IActionResult Delete(int? id)
{
var product = _unitOfWork.Prodcut.GetT(x => x.Id == id);
if (product == null)
{
return Json(new { success = false, message = "Error in fetching Data" });
}
else
{
var oldImagePath = Path.Combine(_webHost.WebRootPath, product.ImageUrl.TrimStart('\\'));
if (System.IO.File.Exists(oldImagePath))
{
System.IO.File.Delete(oldImagePath);
}
_unitOfWork.Prodcut.Delete(product);
_unitOfWork.Save();
return Json(new { success = true, message = "Product Deleted..." });
}
}
#endregion
|
Asked 2/5/2024 7:07:21 PM