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

前端 未结 3 1687
轮回少年
轮回少年 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:07

    You can check Request.HttpMethod for that.

    if (Request.HttpMethod == "POST") {
        //the controller was hit with POST
    }
    else {
        //etc.
    }
    

提交回复
热议问题