I want to use ajax to delete row from database and after delete make refresh for partial view that contain all data
<a class="fa fa-times" href="javascript:DeleteCurrency(@item.CountryID)" title="Delete"></a>
**This is the anchor link that will call javascript function **
function DeleteCurrency(CountryID) {
var Con = confirm("are you sure ?");
if (Con == true) {
$.ajax({
url: "@Url.Action("DeleteCountry","Main")" + CountryID,
type: 'Delete',
async: true,
processData: false,
cache: false,
sucess: function (data) {
alert(dtat);
},
error: function (xhr) {
alert('error');
}
});
}
}
**And this is my controller method for delete **
[HttpDelete]
public ActionResult DeleteCountry(int CountryID)
{
try
{
Country count = db.Countrys.Find(CountryID);
db.Countrys.Remove(count);
db.SaveChanges();
var AllCountries = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList();
ViewBag.Count = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList().Count();
return PartialView("_DetailsOfData", AllCountries);
}
catch (Exception)
{
ViewBag.AlreadyAdded = "يوجد محافظات تابعه لهذه الدوله لا يمكن مسحها";
var AllCountries = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList();
ViewBag.Count = (from cur in db.Countrys orderby cur.govCode ascending select cur).ToList().Count();
return View("AddCountry", AllCountries);
}
}
when i hit anchor link confirm message popup (are you sure?) when click ok all time it enter in error i want to know what is the error