8

Whats the differences between QueryString in Request and RouteData.Values ?
Can we use them instead ?

1 Answer 1

15

RouteValues are gathered from querystring only if are defined in global.asax, for example:

routes.MapRoute(
 "Example", // Route name
 "{controller}/{action}/{id}/{inRouteValues}", // URL with parameters
 new { controller = "Home", action = "Index" } // Parameter defaults
 );

will catch inRouteValues from yourdomain/testController/testAction/14/myTestValue where RouteData.Values["inRouteValues"] will be string with value "myTestValue".
But if you will build URL like yourdomain/testController/testAction/14?inRouteValues=myTestValue it won't get it. So difference is that RouteData.Values will get only values from URLs that match RouteCollectionfrom your global.asax and QueryString will catch every value from your querystring if it matches variable name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.