MVC Routing Parameter Precedence
The query string has nothing at all to do with routing (at least, not unless you customize routing to consider it).
The values that are passed to the ModelBinder
and to your action method are done so by Value Providers. You can control the order of precedence by changing the order in which their corresponding ValueProviderFactory
is registered in the static ValueProviderFactories.Factories
property.
As you can see, the default configuration is to first use the RouteDataValueProviderFactory
and if it returns no value it will try the QueryStringValueProviderFactory
. If you change the order of the factories, the order of precedence changes.
ValueProviderFactories.Factories.RemoveAt(3);
ValueProviderFactories.Factories.Insert(4, new RouteDataValueProviderFactory());