I try to implement DELETE method for my mvc-application.
There is my link placed in View:
@Ajax.ActionLink("Delete", "Delete", "Users", new { userId = user.Id }, new AjaxOptions { HttpMethod = "DELETE" })
There is my controller method:
[HttpDelete]
public ActionResult Delete(string userId)
{
//...
return View("Index");
}
When I click on Delete-link, I get a 404 error.
In Fiddler I see, that my request perfomed by GET method! If I execute DELETE request with the same Headers from Fiddler, I get the expected result - my request is coming right into the Delete method.
How can I use @Ajax.ActionLink
correctly?
P.S.: I want to use only built-in methods.
Are you sure all the Unobtrusive libraries are loaded? An @Ajax.ActionLink
generates a standard anchor tag. If the JavaScript libraries aren't loaded to handle the click event, you'll get the GET request you see in Fiddler.
Check to see if the jquery.unobtrusive-ajax.js
script is included in a bundle that is referenced from your layout page or that you're explicitly loading it on specific pages in a scripts region.