I've always thought that a delete request should be done using type: "DELETE". However, it seems not work in .NET
$.ajax({
type: "GET",
url: '/TestController/DeleteTest?id=10',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data) {
// Works
}
},
error: function (erro) {
console.debug(erro);
}
});
Controller:
[HttpGet]
public JsonResult DeleteTest()
{
int id= Int32.Parse(Request["id"]);
var myTableTest= db.myTable.Where(x => x.id== id).FirstOrDefault();
db.mytable.Remove(myTableTest);
db.SaveChanges();
return Json(true, JsonRequestBehavior.AllowGet);
}
This code works fine! But if I change to type: "DELETE", it won't work anymore. So, does asp.net have HttpDelete?
Thanks