Use DELETE form method in Html.BeginForm()?

别来无恙 提交于 2019-12-19 06:26:19

问题


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?


回答1:


You need this in your form:

@using (Html.BeginForm("Order", "Users"){ 
   @Html.HttpMethodOverride(HttpVerbs.Delete)
}


来源:https://stackoverflow.com/questions/8835450/use-delete-form-method-in-html-beginform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!