-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Url generator in view ignored Area
Name when a another controller has AttributeRoute
#7046
Comments
Area
Name when a other controller with AttributeRoute Area
Name when a another controller has AttributeRoute
@John0King can you upload a complete repro to GitHub so we can take a look? I'm not sure there's enough information here for us to reproduce this. |
@Eilon This is my sample repo , just run it and you can see the different url being generated for |
@John0King thanks for sharing the sample. @jbagga can you take a look? |
See https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas. Attribute routing takes precedence over the conventional "{area}/{controller}/{action}" route you defined in your If this isn't what your issue is, please let me know and I am happy to investigate further! |
@jbagga
If like you said :
why the Url generate correctly when I specific and if this is a normal behaviour then in the document you should told people always specific the |
The ambient values are used to fill in the blanks when you have a conventional route that could be a match. The example you quoted assumes a conventional route only. Specifying area="Admin" in values for If you want precise control of how your controllers are routed to, use attribute routing for your controllers throughout the application. For instance add cc @pranavkm |
and
there no use of and because you share the |
@John0King, to answer your last question: the code you referred to is not thread safe, so you may run into weird issues if you try to call the GetValueDictionary() from another thread. |
May I Ask why there need |
Will this behavior change in asp.net core 2.1 ? I don't use atribute-route now (but I want to), because my |
This behavior will not change. It's by design, attribute routes are preferred to conventional routes.
Because it adds an additional constraint that the attribute route does not meet. The guidance here would be to consistently use attribute routing or conventional routing. Conflating the two, in particular, where your route values appear identical is going to result in the sort of issues you're running in to. |
But if we keep
unless if u in a route url |
We periodically close 'discussion' issues that have not been updated in a long period of time. We apologize if this causes any inconvenience. We ask that if you are still encountering an issue, please log a new issue with updated information and we will investigate. |
MVC version
AspNetCore MVC 2.0.0 on .net Framework 4.6.1
description
when I inside
Admin area
with<a asp-action="Index" asp-controller="News">link</>
, It generate/News
for me,and if I remove the attributeRoute or specific
asp-area="Admin"
it will generate the right url/Admin/News
I don't know why the
ambient values
are ignoredThe text was updated successfully, but these errors were encountered: