[ AcceptVerbs (HttpVerbs. Post)]和[ HttpPost ]有什么区别?

我可以用[ AcceptVerbs (HttpVerbs. Post)]/[ AcceptVerbs (HttpVerbs. Get)]来装饰动作

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(string title)
{
// Do Something...
}

或具有[ HttpPost ]/[ HttpGet ]属性

[HttpPost]
public ActionResult Create(string title)
{
// Do Something...
}

他们不一样吗?

47564 次浏览

Nothing. One is just shorthand for the other.

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