문제

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();
}
도움이 되었습니까?

다른 팁

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

        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top