RC2 : Mixing area inside anchor tag helper generates wrong url
In my _Layout.cshtml, I have built in link who redirects to the homepage (Home/Index)
<a asp-controller="Home" asp-action="Index">WebApplication1</a>
Inside the same layout.cshtml i put another anchor which redirects to an area controller (AreaTest/Test/Index).
<a **asp-area="AreaTest"** asp-controller="Test" asp-action="Index">Go to area</a>
When the page is loaded inside the browser, both of links are ok -Home/Index -AreaTest/Test/Index
If I click on the second link, I'm well redirected to the right page but if i look at the new links generated, the first one which was Home/Index at the first time is became AreaTest/Home/Index.
I joined a little sample
It could be nice to make the tag helpers safe and independent from each other
Note that the workaround is to explicitly fill asp-area attribute on the first anchor with empty value but it's a little bit tricky !
<a asp-area="" asp-controller="Home" asp-action="Index">WebApplication1</a>
I'd like to add the fact that it's the same for action. If we don't specify action in one of our link and another is specifying another action than "Index" for instance, after clicking on the last, the generated url for all links that don't specify explicitly an action will have the action of the clicked link.
Its by design see https://github.com/aspnet/announcements/issues/120.
If you have a view that is reused across areas and that contains links to other parts of the application that are not inside of an area, you should specify that by using asp-area="". The reason for this is that the behavior for areas and link generation is "sticky". When you are inside an area, you don't need to specify the area to produce links to other parts within the same area. What happens in your case is that the first time you visit the home page, you are not inside an area, when you click the link to the action in your area, you are then inside the area, so when you render the view, the first link points to the action and controller within the area.