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

[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)]

扫描二维码关注公众号,回复: 6594629 查看本文章

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")]

转载于:https://www.cnblogs.com/gorgeous1314/archive/2012/07/19/2598761.html

猜你喜欢

转载自blog.csdn.net/weixin_34351321/article/details/93431891
今日推荐