Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Issue: Make UrlHelper.GenerateUrl "collection-aware" [636]

$
0
0
It's a fairly common requirement to want to generate a url which handles collections in a way that is compatible with the default model binder, e.g. see:

http://stackoverflow.com/questions/717690/asp-net-mvc-pass-array-object-as-a-route-value-within-html-actionlink
http://stackoverflow.com/questions/8391055/passing-an-array-to-routevalues-and-have-it-render-model-binder-friendly-url

Basically this would involve special-casing IEnumerable values in a RouteValueDictionary, and generating repeated keys. For example:

routeValues.Add("productId", new[] {1, 3, 5});

would result in a Url being generated something like:

http://server/Controller/Action?productId=1&productId=3&productId=5

As far as I can see with Reflector, the generation of the Url is currently delegated to System.Web.Routing.ParsedRoute.Bind(), which is a Framework class and isn't going to change any time soon.

But this could be achieved in the MVC framework by modifying Url.GenerateUrl as follows:

- Clone the "routeValues" dictionary, and remove all elements whose value is IEnumerable. Pass the cloned dictionary to "routeCollection.GetVirtualPathForArea(requestContext, routeName, values)", which will generate a Url that excludes the IEnumerable routeValues.
- Append the IEnumerable routeValues as queryString parameters.


By making this change in UrlHelper.GenerateUrl, it would automatically become available for all helpers that use UrlHelper.GenerateUrl (UrlHelper.Action, LinkExtensions.ActionLink, etc).
Comments: Hello - We have reviewed this issue and while we agree it would be a cool feature, it is not a sufficiently high priority for us to design, develop, and test it. We recommend using a custom helper method using logic similar to what is described in this issue.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>