[HttpPost] vs [AcceptVerbs(HttpVerbs.Post)](转)

[HttpPost] vs [AcceptVerbs(HttpVerbs.Post)] is there a difference?

 

1、

the HttpPost attribute is a short for the HttpVerbs.Post one but since MVC 2.0. 

 

2、

[HttpPost] is shorthand for [AcceptVerbs(HttpVerbs.Post)].  The only difference is that you can't use [HttpGet, HttpPost] (and similar) together on the same action.  If you want an action to respond to both GETs and POSTs, you must use [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]. 

 

3、

[AcceptVerbs] is the only way to decorate a method that accepts several (but not all) verbs.

[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Put)]

It's also the only way you can specify a verb that's not one of the "core four", such as those which are part of WebDAV:

[AcceptVerbs("LOCK")]

posted @ 2014-08-15 10:52  邹邹  Views(190)  Comments(0)    收藏  举报