【问题标题】: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<T>。
另一种可能性是编写自定义路由以使 url 小写。您可以查看 following blog post,它说明了如何将应用程序中的所有 url 设为小写,但您可以根据需要对其进行调整。