0

I am extending the ActionResult class. In the ExecuteResult method I want to check if the action was a GET or a POST however there doesn't seem property in the ControllerContext class that will let me do that. Does anybody know how to check the request type from a ControllerContext?

public override void ExecuteResult(ControllerContext context)
{
    //See if the request was POST
    if (context.HttpContext.Request.?)
    {
        DoStuff();
    }

    DoOtherStuff();
}
Stefan Bossbaly
  • 6,682
  • 9
  • 53
  • 82
  • 1
    Maybe you can do something similar to [this](http://stackoverflow.com/questions/1169490/c-sharp-asp-net-mvc-find-out-whether-get-or-post-was-invoked-on-controller-acti)? – MilkyWayJoe Jun 28 '12 at 15:09
  • @MilkyWayJoe yes it is. The HttpMethod is buried in the ControllerContext class. Must have overlooked it. – Stefan Bossbaly Jun 28 '12 at 16:02

2 Answers2

2

you can use

context.HttpContext.Request.HttpMethod

http://msdn.microsoft.com/en-us/library/system.web.httprequest.httpmethod%28v=vs.100%29.aspx#Y0

Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122
0

try this:

    public HttpVerbs RequestHttpVerb(ControllerContext context)
    {
        return (HttpVerbs)Enum.Parse(typeof(HttpVerbs), context.HttpContext.Request.HttpMethod, true);
    }

    public override void ExecuteResult(ControllerContext context)
    {
        if (this.RequestHttpVerb(context) == HttpVerbs.Post)
        {

        }
    }
andres descalzo
  • 14,887
  • 13
  • 64
  • 115