Retaining parameters in ASP.NET MVC
- by MapDot
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:
RouteValues.RouteData.Values["showDeleted"] = true;