asp.net MVC api 如何同时支持POST和GET

本人试过,控制器前同时声明 HttpPost 和HttpGet有效

这个简单呀

在contrallor方法头加上名称就行了。


一般的action

[HttpGet]
public ActionResult Index()
{
    Return View()
}

[HttpPost]
public ActionResult Index(string id)
{
    Return View()
}


同时支持get和post的action

 

[ActionName("Index")]
public ActionResult Get()
{
    Return View()
}

[ActionName("Index")]
public ActionResult Post()
{
    Return View()
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-08-06
 [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]

第2个回答  2014-09-15
webapi 支持post get 只需要方法名称是post 和get 就可以了
第3个回答  2014-09-17
这个天然就支持的,主要看你的form提交方式
第4个回答  2014-09-16
同时支持?要干嘛?
请写两个..
相似回答