views:

2933

answers:

4

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?

+6  A: 

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.

Owen
Great answer thanks Owen!
spoon16
I hope that HTML5 increases support for HTTP verbs.
lupefiasco
A: 

So what would be the "best practice" method for executing an HTTP DELETE from the browser?

lupefiasco
+3  A: 

Using XMLHttpRequest, it's not only the "best practice", it's really the only way.

A: 

Use Fiddler or WebScarab

nuwan