[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]区别

1.共同点:[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]都是只接受POST请求过来的数据。

2.不同点:
在MVC中如果想一个action既可以回应POST请求也可以回应GET请求那么我们应该怎么做呢?
首先[HttpPost]和[HttpGet]是不能同时存在一个action上
但是[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]可以

写法:

 [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
 public ActionResult Index()
 {
     //TODO:
 }

 

 

[AcceptVerbs("POST","GET")]
public ActionResult About() { return View(); }

 

posted @ 2021-05-10 17:21  qingjiawen  阅读(111)  评论(0编辑  收藏  举报