I'm new with and using ASP.NET, MVC3 and AJAX.
I try to call a method in my controller with an AJAX call, but I receive an Internal Server Error.
Here's my Javascript method:
function DeleteItem(id) {
var answer = confirm("Are you sure ?")
if(answer) {
$.ajax({
type: 'POST',
url: '/Item/Delete',
data: id,
dataType: 'json',
success: function (data) {
alert('Function called');
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
}
and here's my method in my Controller:
public ActionResult Delete(int idItem) {
Item.Delete(idItem); //delete my item
return RedirectToAction("Index", "Item");
}
The Javascript method is called, but when I answer "Yes, I'm sure I want to delete", I get an Internal Server Error and I am not sure why. What causes the server error?