Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get route values from inside my ActionExecuting filter?

How can I get route values from inside my OnActionExecuting filter method.

I had the following two suggestions but I am still confused:

  1. Access your ControllerContext in the method and that gives you access to RouteValues so filterContext.Controller.RouteValues
  2. Access filterContext.Controller.RouteValues

I have for example the method:

public ActionResult Delete(string city, string street) {
    //enter code here
}

If I want to get the value of city and street then how can I do this. Sorry if it seems like a basic question but I am not sure how to get access to the above.

like image 732
Samantha J T Star Avatar asked Dec 24 '11 03:12

Samantha J T Star


2 Answers

Here it is,

    protected override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var parameters = filterContext.ActionParameters;
        var email = parameters["email"];
        var city = parameters["city"];
    }
like image 142
imran_ku07 Avatar answered Oct 06 '22 00:10

imran_ku07


I think you're trying to preempt some controller action (like Delete) with "enter code here":

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    string city = filterContext.ActionParameters["city"];
    string street = filterContext.ActionParameters["street"];

    // probably include this:
    //base.OnActionExecuting(filterContext);
}
like image 39
David Fox Avatar answered Oct 05 '22 23:10

David Fox