从ActionResult获取请求类型

时间:2012-06-28 15:05:39

标签: c# asp.net-mvc-3 post actionresult controllercontext

我正在扩展ActionResult课程。在ExecuteResult方法中,我想检查操作是GET还是POST但是ControllerContext类似乎没有让我这样做的属性。有人知道如何从ControllerContext检查请求类型吗?

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

    DoOtherStuff();
}

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

试试这个:

    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)
        {

        }
    }