Question

When you use MvcContrib grid sorting out-of-the-box, it automatically appends the querystrings Column and Direction to your URL. For instance:

www.mysite.com/listing?Column=Bedrooms&Direction=Ascending

Is there a way to lowercase the querystrings (Column and Direction) so that you get this:

www.mysite.com/listing?column=Bedrooms&direction=Ascending

I'm using ASP.NET MVC 3 with MvcContrib version 3.

Was it helpful?

Solution

Unfortunately those values are hardcoded in the MvcContrib.UI.Grid.HtmlTableGridRenderer<T> class:

// MvcContrib.UI.Grid.HtmlTableGridRenderer<T>
private RouteValueDictionary CreateRouteValuesForSortOptions(GridSortOptions sortOptions, string prefix)
{
    if (string.IsNullOrEmpty(prefix))
    {
        return new RouteValueDictionary(sortOptions);
    }
    return new RouteValueDictionary(new Dictionary<string, object>
    {
        {
            prefix + ".Column", 
            sortOptions.Column
        }, 
        {
            prefix + ".Direction", 
            sortOptions.Direction
        }
    });
}

The CreateRouteValuesForSortOptions private method is invoked by the RenderHeaderText virtual protected method. So if you want to have lowercase parameter names one possibility would be to write a custom GridRenderer<T>.

Another possibility is to write a custom Route to make urls lowercase. You may take a look at the following blog post which illustrates how to make all urls in an application to be lowercase but you could tweak it to your needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top