Lets say we have this route:
routes.MapRoute(
"Library",
"Lib/{id}/{lang}",
New With {.controller = "MyLibrary", .action = "ShowItem", .id= 0, .lang = "en"}
)
And lets say we request this url:
http://localhost/Lib/10/de
so now we have this route values: id = 10 & lang = de
Here is the problem:
This code:
<%= Url.Action("ShowItem", New With {.id = 45})%>
returns:
http://localhost/Lib/45/de
It changes id but preserves lang.
But this code:
<%= Url.RouteUrl("Library", New With {.id = 45})%>
returns:
http://localhost/Lib/45
It changes id but removes lang!
Is this a bug or what? I know how to fix this, but this different behavior is very confusing. Am I right? Or just imagining this?
One quick fix would be:
<%= Url.RouteUrl("Library", New With {.id = 45},.lang = RouteData.Values("lang"))%>