Any way to handle Put and Delete verbs in ASP.Net MVC?

删除回忆录丶 提交于 2020-01-01 06:52:09

问题


just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview 5 preferably.


回答1:


Check out the mvccontrib project at http://www.mvccontrib.org. In the source code a restful implementation has been added and it is current up to Preview 5. Check out the source code here - http://mvccontrib.googlecode.com/svn/trunk/src/MVCContrib/SimplyRestful




回答2:


Rails uses a "method" parameter in the form and then fakes it, but calls the appropriate method if you designate it.
I understand most clients won't support restful stack, but can asp.net mvc, auto-negotiate these verbs and place them in the appropriately deemed actions?




回答3:


I've been covering this in my blog http://shouldersofgiants.co.uk/blog/ where I'm looking at an entire RESTful web service based on ASP.Net and MVC




回答4:


I don't know of one off the top of my head, but you might look into the way that Rails handles it if you don't find anything else, and try porting it over. Rails utilizes POST, GET, PUT, and DELETE, but it apparently has to do some fakery for PUT. Could be worth looking into if you come up dry here.




回答5:


I think that the new AcceptVerbsAttribute in preview 5 should be capable of directing any type of request to a designated action. Marking a method like below in theory allows handling of all verbs but I haven't explicitly tested put or delete.

[AcceptVerbs("delete")]
public object DoDeleteAction()



回答6:


With MVC Beta, u can now use an HttpVerbs enumeration.

here's an example...

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Index()
{ ... }

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update()
{ ... }

[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult Delete()
{ ... }

you get the idea.

hth :)



来源:https://stackoverflow.com/questions/46644/any-way-to-handle-put-and-delete-verbs-in-asp-net-mvc

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