Samantha J T Star
Samantha J T Star

Reputation: 32808

How can I tell if a method is a result of a get or a post from inside my MVC action filter?

I have methods like this:

    [HttpPost]
    public ActionResult Delete(BaseViewModel vm) {

    public ActionResult Delete(string ac) {
        try {

From within my action filter is there a way that I can check if the method is a post or get ?

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {

??

Upvotes: 18

Views: 7624

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239694

The ActionExecutingContext has a HttpContext property. From there, you can obtain the Request property, which has a HttpMethod property, which tells you which method was used in this request.

Upvotes: 41

Related Questions