C# ASP.NET MVC: Find out whether GET or POST was invoked on controller action

前端 未结 3 1688
轮回少年
轮回少年 2021-02-19 09:28

How do I find out whether a GET or a POST hit my ASP.NET MVC controller action?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 10:05

    You can also use the ActionResults For Get and Post methods separately as below:

    [HttpGet]
    public ActionResult Operation()
    {
    
       return View(...)
    }
    
    
    [HttpPost]
    public ActionResult Operation(SomeModel model)
    {
    
       return View(...);
    }
    

提交回复
热议问题