Monday, July 18, 2011

MVC3 Webgrid HTML helper Initial Descending Sorting

Monday, July 18, 2011 Posted by Andre Broers , , , , 8 comments
There is no option in the webgrid constructor to set the initial sort order. By default it wil sort ascending. When you have a list of dates and want to sort this in descending order you can do it the following way:

Add the following lines of razor code just behind the creation of the webgrid helper:
if (Request.QueryString[prigrid.SortDirectionFieldName].IsEmpty()) {
  prigrid.SortDirection = SortDirection.Descending;

When no sorting is selected it will set the order to descending.


  1. Do you have a input on webgrid grouping? Subscribed to your feed and would love your gentle approach to grouping using the MVC3 webgrid