1 /* ****************************************************************************
\r
3 * Copyright (c) Microsoft Corporation. All rights reserved.
\r
5 * This software is subject to the Microsoft Public License (Ms-PL).
\r
6 * A copy of the license can be found in the license.htm file included
\r
7 * in this distribution.
\r
9 * You must not remove this notice, or any other, from this software.
\r
11 * ***************************************************************************/
\r
13 namespace System.Web.Mvc {
\r
14 using System.Collections.Generic;
\r
15 using System.Web.Routing;
\r
17 internal static class RouteValuesHelpers {
\r
18 public static RouteValueDictionary GetRouteValues(RouteValueDictionary routeValues) {
\r
19 return (routeValues != null) ? new RouteValueDictionary(routeValues) : new RouteValueDictionary();
\r
22 public static RouteValueDictionary MergeRouteValues(string actionName, string controllerName, RouteValueDictionary implicitRouteValues, RouteValueDictionary routeValues, bool includeImplicitMvcValues) {
\r
23 // Create a new dictionary containing implicit and auto-generated values
\r
24 RouteValueDictionary mergedRouteValues = new RouteValueDictionary();
\r
26 if (includeImplicitMvcValues) {
\r
27 // We only include MVC-specific values like 'controller' and 'action' if we are generating an action link.
\r
28 // If we are generating a route link [as to MapRoute("Foo", "any/url", new { controller = ... })], including
\r
29 // the current controller name will cause the route match to fail if the current controller is not the same
\r
30 // as the destination controller.
\r
32 object implicitValue;
\r
33 if (implicitRouteValues != null && implicitRouteValues.TryGetValue("action", out implicitValue)) {
\r
34 mergedRouteValues["action"] = implicitValue;
\r
37 if (implicitRouteValues != null && implicitRouteValues.TryGetValue("controller", out implicitValue)) {
\r
38 mergedRouteValues["controller"] = implicitValue;
\r
42 // Merge values from the user's dictionary/object
\r
43 if (routeValues != null) {
\r
44 foreach (KeyValuePair<string, object> routeElement in GetRouteValues(routeValues)) {
\r
45 mergedRouteValues[routeElement.Key] = routeElement.Value;
\r
49 // Merge explicit parameters when not null
\r
50 if (actionName != null) {
\r
51 mergedRouteValues["action"] = actionName;
\r
54 if (controllerName != null) {
\r
55 mergedRouteValues["controller"] = controllerName;
\r
58 return mergedRouteValues;
\r