Why does this MVC action return a 404 response in IE11

400 views Asked by At

I have written an mvc action that works in Chrome and Firefox but not in IE11. Using IE11 it returns a 404 response code.

Controller:

[HttpDelete]
public ActionResult DeleteAction(int ActionID)
{
    return Json(_Logic.DeleteAction(ActionID), JsonRequestBehavior.DenyGet);
}

Calling JS:

Ajax_Proxy.DeleteAction = function (_actionID, successCallback, failureCallback) {
    return $.ajax({
        type: "DELETE",
        datatype: 'json',
        url: "/root/someurl/DeleteAction?ActionId=" + _actionID,
        contentType: 'application/json; charset=utf-8',
        success: function (data) { successCallback(_actionID, data); },
        error: function (data) { failureCallback(data); },
    });
};

The Url I am accessing is correct, as it works in other browsers. Has anyone seen this before?

2

There are 2 answers

1
Piotr Leniartek On BEST ANSWER

Beacuse you say that it works in Chrome and Firefox I assume you enabled PUT/Delete methods on the IIS?

If yes, I think this may be problem that some IE browsers doesn't support type: "DELETE" in Ajax calls. Maybe you are using compability mode to IE8 or something like that?

This problem was already mentioned on SO here: Problem with jQuery.ajax with 'delete' method in ie maybe you just discover that IE11 also doesn't support DELETE.

Another one good discusion Are the PUT, DELETE, HEAD, etc methods available in most web browsers?

0
joaoeduardorf On

Try this.

Ajax_Proxy.DeleteAction = function (_actionID, successCallback, failureCallback) {
return $.ajax({
    type: "DELETE",
    datatype: 'json',
    url: '@Url.Content("~/root/someurl/DeleteAction/")' + _actionID,
    contentType: 'application/json; charset=utf-8',
    success: function (data) { successCallback(_actionID, data); },
    error: function (data) { failureCallback(data); },
});

};