Retaining parameters in ASP.NET MVC

Posted by MapDot on Stack Overflow See other posts from Stack Overflow or by MapDot
Published on 2010-06-10T17:21:15Z Indexed on 2010/06/10 17:22 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

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;

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET