Geeks With Blogs
Etienne Giust's .NET notes Some .NET tips and tricks for me to remember. That might help you too

 

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:

http://www.mysite.com/myapplication/User/Edit/1234

 

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 :

http://www.mysite.com/myapplication/User/Edit/1234?OfficeId=567

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

Posted on Thursday, May 3, 2012 2:08 AM | Back to top


Comments on this post: filterContext.RouteData.Values null ?

# re: filterContext.RouteData.Values null ?
Requesting Gravatar...
Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! the original source
Left by Robinjack on Mar 17, 2018 7:01 PM

Your comment:
 (will show your gravatar)


Copyright © Etienne Giust | Powered by: GeeksWithBlogs.net