【问题标题】:MvcContrib grid lowercase sorting querystringsMvcContrib 网格小写排序查询字符串
【发布时间】:2011-09-10 16:48:50
【问题描述】:

当您使用开箱即用的 MvcContrib 网格排序时,它会自动将查询字符串 Column 和 Direction 附加到您的 URL。例如:

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

有没有办法将查询字符串(列和方向)小写以便得到:

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

我正在使用带有 MvcContrib 版本 3 的 ASP.NET MVC 3。

【问题讨论】:

    标签: asp.net-mvc-3 mvccontrib mvccontrib-grid


    【解决方案1】:

    不幸的是,这些值被硬编码在 MvcContrib.UI.Grid.HtmlTableGridRenderer<T> 类中:

    // 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
            }
        });
    }
    

    CreateRouteValuesForSortOptions 私有方法由RenderHeaderText 虚拟保护方法调用。因此,如果您想使用小写参数名称,一种可能性是编写自定义 GridRenderer&lt;T&gt;

    另一种可能性是编写自定义路由以使 url 小写。您可以查看 following blog post,它说明了如何将应用程序中的所有 url 设为小写,但您可以根据需要对其进行调整。

    【讨论】:

      猜你喜欢
      • 2011-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 2018-05-05
      • 2012-11-18
      • 1970-01-01
      相关资源
      最近更新 更多