-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Unexpected Url.Action output #2859
Comments
@Muchiachio is there a typo in your sample? If not where would "NotHome" come from? |
No, I just didn't want to write "Broken" in the issue 😄 |
@Muchiachio my point was the |
Hmm, but you didn't need to specify other controllers in MVC5 routing, right? @Url.Action("Index", new { custom = "Double" }) would mean, form an url for current controller and area + add custom route value/query parameter? @Url.Action("Index", new { controller = ViewContext.RouteData.Values["controller"], custom = "Double" }) |
That depends on the current value of Ex: - using route:
Current Values: In this case, the current (or 'ambient') value of Current Values: In this case, the current (or 'ambient') value of |
Does that mean that there are changes in routing in MVC6? |
The same routing logic should be in MVC5 and MVC6 with respect to this... |
The only intended behavior difference between MVC 5 and MVC 6 is that MVC 6 won't generate a link to something that doesn't exist. I'll take a look at the samples. |
I can confirm that this is behaving differently on MVC6. Currently trying to root cause why. Thanks for the report and the helpful repos 👍 |
Found the issue here. There's a piece of code in http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/RouteValuesHelpers.cs In effect, if you call |
Ah yes I vaguely recall that. |
This change restores a link generation behavior from MVC5 and earlier where 'action' and 'controller' values are special cased-when using Url.Action(...). The change is that in-effect 'action' and 'controller' are always included in the route values given to the routing system. Passing a null value into the Url.Action(...) method means that the ambient value for that token should be used explicitly. This means that the 'action' and 'controller' tokens become sticky, even when something to the lexical left in the URL (like area) changes.
Given routing in beta5:
And calling this from NotHome controller view
results in
/Double
while expected output is
/Double/NotHome
The text was updated successfully, but these errors were encountered: