From 6e10aef2597309a45a4f1b247e872fad8ba1e11b Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Wed, 30 Jul 2014 13:41:17 +0700 Subject: [PATCH] Fix for using preservedRouteParameters so they will work whether the value is provided as part of the route or part of the query string. The route value collection contained an empty value for "id" (which was configured in the route as optional). This caused the route value to take precedence even though it was empty. To match the behavior MVC, the query string value was made to overwrite the route value in this case. Route values still take precedence over query string values when both are provided. --- src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs index 2777e595..c9b5daf8 100644 --- a/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs +++ b/src/MvcSiteMapProvider/MvcSiteMapProvider/SiteMapNode.cs @@ -726,8 +726,9 @@ protected virtual IDictionary MergeRouteValuesAndNamedQueryStrin { // Copy the query string value as a route value if it doesn't already exist // and the name is provided as a match. Note that route values will take - // precedence over query string parameters in cases of duplicates. - if (key != null && queryStringKeys.Contains(key) && !result.ContainsKey(key)) + // precedence over query string parameters in cases of duplicates + // (unless the route value contains an empty value, then overwrite). + if (key != null && queryStringKeys.Contains(key) && (!result.ContainsKey(key) || string.IsNullOrEmpty(result[key].ToString()))) { result[key] = queryStringValues[key]; }