How to pass an action method anti-fake token with the HttpDelete attribute in ASP.NET MVC?

Is it possible?

The code looks like this ...

[Transaction]
[ValidateAntiForgeryToken]
[HttpDelete]
public ActionResult Delete(int id) { ...}
+3
source share
1 answer

The following assistant can be added to the form:

<%= Html.HttpMethodOverride(HttpVerbs.Delete) %>

This will include a hidden field that will instruct the framework to trigger the correct action of the controller. Now there are two possibilities:

  • Normal html form submit: only POST is supported, therefore it will be used, but due to the hidden field the correct action of the controller will be called.
  • AJAX: you can use any desired verb, including DELETE, to serialize the input values โ€‹โ€‹of the form and submit them - there is no problem.
+5
source

Source: https://habr.com/ru/post/1770455/


All Articles