Detect if action is a POST or GET method

前端 未结 4 1252
孤街浪徒
孤街浪徒 2020-12-14 00:01

In MVC 3, is it possible to determine if an action is a result of a POST or GET method? I know you can decorate the actions with [HttpPost] and [HttpGet] to fire a specific

4条回答
  •  独厮守ぢ
    2020-12-14 00:45

    If you're like me and prefer not to use a string literal (.net core 2.2 middleware using DI):

    public async Task InvokeAsync(HttpContext context)
    {
        if (context.Request.Method.Equals(HttpMethods.Get, StringComparison.OrdinalIgnoreCase))
        {
            …
        }
    }
    

提交回复
热议问题