Question

I'd like to use the appropriate HTTP method when possible. In this case, when a button is clicked to delete something, I want to fire the controller action with the attribute [HttpDelete]. However, I can't seem to create a form with this method - using Razor syntax. The FormMethod enum does not have an option for Delete and doing the following doesn't override it:

@using (Html.BeginForm("Order", "Users", FormMethod.Post, new { method = "DELETE" }))

Searching for solutions yields none, is nobody doing this? I know I can just use POST but isn't this the point of the HTTP delete method to begin with?

Était-ce utile?

La solution

You need this in your form:

@using (Html.BeginForm("Order", "Users"){ 
   @Html.HttpMethodOverride(HttpVerbs.Delete)
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top