是否有可能触发一个HTTP DELETE从HTML表单请求? [英] Is it possible to trigger an HTTP DELETE request from an HTML form?

查看:260
本文介绍了是否有可能触发一个HTTP DELETE从HTML表单请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC项目,我有一个接受GET,POST和DELETE请求一个动作。每种类型的请求通过过滤属性我控制器动作方法。

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)

我有我的 GraphAdd 方法工作得很好。我试图搞清楚的是如何建立一个HTML <形式/> < A /> (链接),这将导致浏览器执行HTTP请求,删除和触发我GraphDelete方法。

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.

如果有一种方法可以做到这可以有人张贴一些示例HTML,如果现有的MVC的HtmlHelper方法,我应该使用?

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?

推荐答案

我不相信这是可能的。在HTML4和放大器表单元素的方法属性; XHTML 1.0将只接受GET或POST。此外,大多数网络服务器的标准CONFIGS将拒绝删除和PUT请求。假设你已经配置你的Web服务器,才允许PUT方法/ DELETE(例如WebDAV一样),然后你可以创建自己的HTTP请求:

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

和适当地处理它。但是,有没有办法通过当前HTML表单做到这一点。利息的缘故,有对HTML5支持DELETE一些讨论

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.

这篇关于是否有可能触发一个HTTP DELETE从HTML表单请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆