GetVirtualPath not making any sense.
Posted
by HeavyWave
on Stack Overflow
See other posts from Stack Overflow
or by HeavyWave
Published on 2010-03-09T10:32:53Z
Indexed on
2010/03/09
10:36 UTC
Read the original article
Hit count: 499
asp.net-mvc
|c#
Can anyone explain why this code with the given routes returns the first route?
routes.MapRoute(null, "user/approve", new { controller = "Users", action = "Approve" }),
routes.MapRoute(null, "user/{username}", new { controller = "Users", action = "Profile" }),
routes.MapRoute(null, "user/{username}/{action}", new { controller = "Users" }),
routes.MapRoute(null, "user/{username}/{action}/{id}", new { controller = "Users" }),
routes.MapRoute(null, "search/{query}", new { controller = "Artists", action = "Search", page = 1 }),
routes.MapRoute(null, "search/{query}/{page}", new { controller = "Artists", action = "Search" }),
routes.MapRoute(null, "music", new { controller = "Artists", action = "Index", page = 1 }),
routes.MapRoute(null, "music/page/{page}", new { controller = "Artists", action = "Index" })
var pageLinkValueDictionary = new RouteValueDictionary(this.linkWithoutPageValuesDictionary);
pageLinkValueDictionary.Add("page", pageNumber);
var virtualPathData = RouteTable.Routes.GetVirtualPath(this.viewContext.RequestContext, pageLinkValueDictionary);
Here GetVirtualPath always returns user/approve, although there is no {page} parameter in the route. Furthermore, everything works as expected without the first route.
I have found this link http://www.codeplex.com/aspnet/WorkItem/View.aspx?WorkItemId=2033 but it wasn't very helpful. It looks like GetVirtualPath was not implemented with large collections of routes in mind.
I am using ASP.Net MVC 1.0.
© Stack Overflow or respective owner