Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to trigger an HTTP DELETE request from an HTML form?

I have an ASP.NET MVC project and I have a single action that accepts GET, POST, and DELETE requests. Each type of request is filtered via attributes on my controllers Action methods.

[ActionName(Constants.AdministrationGraphDashboardAction),
AcceptVerbs(HttpVerbs.Post)]
public ActionResult GraphAdd([ModelBinder(typeof (GraphDescriptorBinder))] GraphDescriptor details);

[ActionName(Constants.AdministrationGraphDashboardAction),
AcceptVerbs(HttpVerbs.Delete)]
public ActionResult GraphDelete([ModelBinder(typeof (RdfUriBinder))] RdfUri graphUri)

I have my GraphAdd method working very well. What I'm trying to figure out is how I can create an HTML <form /> or <a /> (link) that will cause the browser to perform an HTTP Delete request and trigger my GraphDelete method.

If there is a way to do this can someone post some sample HTML and if available the MVC HtmlHelper method I should be using?

like image 940
Eric Schoonover Avatar asked Nov 10 '08 05:11

Eric Schoonover


People also ask

Does http delete have request body?

client:http service does not include a body in requests that use the DELETE method. It is common practice to qualify HTTP DELETE requests by including query parameters in the URL. While it is not explicitly forbidden to include a body with a DELETE request, most HTTP servers do not support it.

Does a delete request have a response?

Responses. If a DELETE method is successfully applied, there are several response status codes possible: A 202 ( Accepted ) status code if the action will likely succeed but has not yet been enacted. A 204 ( No Content ) status code if the action has been enacted and no further information is to be supplied.

How do you use put and delete in HTML?

Browsers do support PUT and DELETE but it only by using request via AJAX, but not via 'HTML form' submission. In both HTML4 and HTML5 spec, it says that the only HTTP methods that HTML form element should allow are "GET" and "POST". There is no clear reason why PUT and DELETE are not supported by 'HTML form'.


1 Answers

i don't believe this is possible. the method attribute of form elements in HTML4 & XHTML 1.0 will only accept GET or POST. in addition, standard configs of most webservers will deny DELETE and PUT requests. assuming you have configured your webserver to allow methods like PUT / DELETE (such as WebDav does), you could then create your own HTTP request:

DELETE /resource.html HTTP/1.1
Host: domain.com

and handle it appropriately. however, there's no way to do this via a current HTML form. for interest's sake, there is some discussion for DELETE support in HTML5.

like image 200
Owen Avatar answered Sep 21 '22 19:09

Owen