Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

??

like image 360
Samantha J T Star Avatar asked Dec 25 '11 12:12

Samantha J T Star


People also ask

How can we detect that an MVC controller is called by post or get?

You can check the Request. HttpMethod property.

What are the two methods defined by action filter?

Action Filter is an attribute that you can apply to a controller action or an entire controller. This filter will be called before and after the action starts executing and after the action has executed. Action filters implement the IActionFilter interface that has two methods OnActionExecuting andOnActionExecuted.


1 Answers

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.

like image 104
Damien_The_Unbeliever Avatar answered Feb 07 '23 04:02

Damien_The_Unbeliever