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

前端 未结 3 1685
轮回少年
轮回少年 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 09:48

    You can separate your controller methods:

    [AcceptVerbs(HttpVerbs.Get)]
    public ViewResult Operation()
    {
       // insert here the GET logic
       return SomeView(...)
    }
    
    
    [AcceptVerbs(HttpVerbs.Post)]
    public ViewResult Operation(SomeModel model)
    {
       // insert here the POST logic
       return SomeView(...);
    }
    

提交回复
热议问题