开发者

MvcContrib grid lowercase sorting querystrings

开发者 https://www.devze.com 2023-04-04 04:00 出处:网络
When you use MvcContrib grid sorting out-of-the-box, it automatically appends the querystrings Column and开发者_如何学Python Direction to your URL. For instance:

When you use MvcContrib grid sorting out-of-the-box, it automatically appends the querystrings Column and开发者_如何学Python 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号