How MVC WebGrid updates the query string

When you enable paging and sorting in MVC WebGrid, it automatically adds the sorting and page options to the query string automatically. How does it do it? I understand how it creates a link for page n, but how to do this if you read the query string to find out which page to produce?

What really bothers me is that in the controller I do not need to specify the page and sort options, but they work anyway. What kind of witchcraft is this?

if I was not clear enough

here is a grid definition

@{ var grid = new WebGrid(Model.Customers, rowsPerPage: 25, canPage: true }); }

here is the query string that is created:

/Customer?sort=Notes&sortdir=ASC

and my Customer.Index controller

//no parameters here. how does WebGrid maintain querystring?
public ActionResult Index() 
{
    ...
}
+3
source share
1 answer

, HttpContext.Request.QueryString, .

, , :

    public string SortColumn {
        get { 
            if (!_sortColumnSet) { 
                string sortColumn = QueryString[SortFieldName];
                // blah blah blah
            } 
            // blah blah blah
            return _sortColumn;
        } 
        set {
            // blah blah blah omitted for brevity
        } 
    }
+2