I’m using ASP.NET MVC 3.
I was used to rely on filterContext.RouteData.Values to get parameters from the url
var idEdited = filterContext.RouteData.Values["id"];
This works fine as long as the url does not have specific parameters, like here:
However, when the parameter is not a routevalue anymore, like in the example below, then you would get a OfficeId= null when using the previous method :
When you are in that case, there is a way to get both the route value “id” and the parameter “OfficeId” using the ValueProvider :
var idEdited = filterContext.Controller.ValueProvider.GetValue("id").AttemptedValue;
var idEditedOffice = filterContext.Controller.ValueProvider.GetValue("OfficeId").AttemptedValue;
The ValueProvider will search into route values and url parameters (also in POST parameters, apparently).
thanks to http://stackoverflow.com/questions/6998809/question-about-routedata-and-valueprovider-on-asp-net-mvc3