This is a migrated thread and some comments may be shown as answers.

[Solved] Improving GridRouteValues extension

0 Answers 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Roma
Top achievements
Rank 1
Roma asked on 09 Sep 2011, 03:29 PM
Hello Telerik, I add condition key != null, couse Request.Param is NameValueCollection, where key can be null.

        
public static RouteValueDictionary GetGridRouteValues(this ControllerBase controller)
        {
            var routeValues = new RouteValueDictionary();
 
            foreach (string key in controller.ControllerContext.HttpContext.Request.Params)
            {
                if (null != key)
                {
                    if (key.EndsWith(GridUrlParameters.CurrentPage, StringComparison.OrdinalIgnoreCase) ||
                        key.EndsWith(GridUrlParameters.Filter, StringComparison.OrdinalIgnoreCase) ||
                        key.EndsWith(GridUrlParameters.OrderBy, StringComparison.OrdinalIgnoreCase) ||
                        key.EndsWith(GridUrlParameters.GroupBy, StringComparison.OrdinalIgnoreCase) ||
                        key.EndsWith(GridUrlParameters.PageSize, StringComparison.OrdinalIgnoreCase))
                    {
                        routeValues[key] = controller.ControllerContext.HttpContext.Request.Params[key];
                    }
                }
            }
 
            return routeValues;
        }
Tags
Grid
Asked by
Roma
Top achievements
Rank 1
Share this question
or