views:

65

answers:

1

Many MVC frameworks (e.g. PHP's Zend Framework) have a way of providing basic state management through URLs. The basic principle is this:

Any parameters that were not explicitly modified or un-set get copied into every URL

For instance, consider a listing with pagination. You'll have the order, direction and page number passed as URL parameters. You may also have a couple of filters. Changing the value of a filter should not alter the sort order.

ASP.net MVC seems to remember your controller and action by default:

<%: Html.RouteLink("Next", "MyRoute", new {id = next.ItemId}) %>

This will not re-set your action or controller. However, it does seem to forget all other parameters. The same is true of ActionLink.

Parameters that get set earlier on in your URL seem to get retained as well.

Is there a way to make it retain more than that?

For instance, this does not seem to affect any of the links being generated:

RouteData.Values["showDeleted"] = true;
A: 

The easiest solution to remembering paging and sorting parameters is to have a client side tool (like jqGrid) do the management for you.

ActionLink won't remember parameters because that's not it's job. It is designed to provide a link (completely independent of what page you're currently on) to another page.

Based on the links you shared, it looks like you want to remember the filtering parameters while going to another page and then returning to the list. In my application I implemented popup modals to handle commands, leaving jqGrid in the background. Another solution is to keep the filtering parameters in the session, but that can lead to confusing behavior if a user opens two copies of the same page.

Ryan