views:

26

answers:

1

I'm working on a project that requires me to sort a column of a list and the list is several pages long. Currently, when I sort, everything sorts correctly, and when I go to the next page, it does just that. My problem is that once I sort and go to the next page, I lose my sort value.

I'm using the ActionLink Html helper method to generate my page links, but the page links do not include my route value from the last link for sorting. How can I make ActionLink use route values from my previous route?

A: 

A solution uses the HttpContext.Current.Request property.

In the header section (where sorting is set), I added the following:

<%: Html.ActionLink("linkText", "actionName", new { sort = "sortingName", page = HttpContext.Current.Request["page"] })%>

and in the paging section, I added the following:

<%: Html.ActionLink(i.ToString(), "actionName", new { page = i, sort = HttpContext.Current.Request["sort"]})

This will use your previous url's route values.

David Benham