PUT or DELETE verb in ASP.NET MVC on HTML form

后端 未结 3 881
北恋
北恋 2021-01-04 07:42

I have a simple user registration form, with two fields, one for username and another for the password. I have a controller called UserController which has thes

3条回答
  •  执念已碎
    2021-01-04 08:11

    Since no one really answered it here, I'll add my .02

    MVC adds the following field to the html form (used for example when using Html.BeginForm()) to support this. Even though HttpPut and HttpDelete are not actually supported for Html5 (they were at one point and then removed from the draft specification), the server libs for MVC will properly route the request to your HttpDelete or HttpPut method when the following form field is posted with your HttpPost request:

    
    @using (Html.BeginForm("SomeAction"){ 
       @Html.HttpMethodOverride(HttpVerbs.Delete)
    }
    
    

提交回复
热议问题