When pressing the delete button it successfully delete the record from database. But not delete from the frontend it gives result after reloading or refreshing the page.
My view:
@foreach (var item in Model)
{
<a href="#" class="phone_number" onclick="del(this)" data-id="@item.id">
<i class="fas fa-trash-alt"></i>
</a>
}
<script>
function del(x) {
var url = '@Url.Action("deleteRent", "Home")';
var rd = x.dataset.id
debugger
$.ajax({
url: url,
type: 'POST',
data: {
id: rd
},
success: function (data) {
if (data.length == 0) // No errors
alert("Delete success!");
},
error: function (jqXHR) { // Http Status is not 200
},
complete: function (jqXHR, status) { // Whether success or error it enters here
}
});
};
</script>
2
Answers
Please add window.location.reload() code after alert….
this code automatically reload your page after success
Actually you delete from database but you don’t refresh your page.
Either, you use answer from Dipendrasinh Vaghela and you refresh the whole page.
Or if you have a function which search and show in DOM, you call it when delete is success. That’ll update "only" the part showing datas.