pallu
2/26/2012 - 8:42 PM

http://stackoverflow.com/questions/9442494/asp-net-mvc-the-right-way-to-propagate-query-parameter-through-all-actionlinks

private class QueryPropagatingRoute : RouteBase {
    private readonly RouteBase target;
    private readonly string[] queryStringKeys;

    public QueryPropagatingRoute(RouteBase target, params string[] queryStringKeys) {
        this.target = target;
        this.queryStringKeys = queryStringKeys;
    }

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
        foreach (var key in this.queryStringKeys) {
            if (values.ContainsKey(key))
                continue;

            values.Add(key, requestContext.HttpContext.Request.QueryString[key]);
        }
        var path = target.GetVirtualPath(requestContext, values);

        return path;
    }

    public override RouteData GetRouteData(HttpContextBase httpContext) {
        return target.GetRouteData(httpContext);
    }
}