Skip to content

Link is mis-rendering based on the current page #24455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SoftCircuits opened this issue Jul 30, 2020 · 9 comments
Closed

Link is mis-rendering based on the current page #24455

SoftCircuits opened this issue Jul 30, 2020 · 9 comments
Assignees
Labels
affected-most This issue impacts most of the customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-routing ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. severity-minor This label is used by an internal tool Status: Resolved

Comments

@SoftCircuits
Copy link

SoftCircuits commented Jul 30, 2020

I have a Razor Pages application with the following markup in my _Layout.cshtml file.

<li class="nav-item dropdown">
    <a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Reports
    </a>
    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" asp-area="Reports" asp-page="/Invoice/Index">Invoices</a>
        <div class="dropdown-divider"></div>
        <a class="dropdown-item" asp-area="Reports" asp-page="/ProfitabilityByCustomer/Index">Profitability by Customer</a>
        <a class="dropdown-item" asp-area="Reports" asp-page="/ProfitabilityByLocation/Index">Profitability by Location</a>
        <a class="dropdown-item" asp-area="Reports" asp-page="/CostAudit/Index">Cost Audit</a>
        <a class="dropdown-item" asp-area="Reports" asp-page="/ChangeLogs/Index">Change Logs</a>
    </div>
</li>

Notice the last link (to /ChangeLogs/Index). This page has a page route (@page "{id?}").

This markup appeared to be rendering correctly. But then I manually navigated to /Reports/ChangeLogs/61, and the markup above rendered as:

<li class="nav-item dropdown">
    <a class="nav-link text-dark dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Reports
    </a>
    <div class="dropdown-menu" aria-labelledby="navbarDropdown">
        <a class="dropdown-item" href="/Reports/Invoice">Invoices</a>
        <div class="dropdown-divider"></div>
        <a class="dropdown-item" href="/Reports/ProfitabilityByCustomer">Profitability by Customer</a>
        <a class="dropdown-item" href="/Reports/ProfitabilityByLocation">Profitability by Location</a>
        <a class="dropdown-item" href="/Reports/CostAudit">Cost Audit</a>
        <a class="dropdown-item" href="/Reports/ChangeLogs/61">Change Logs</a>
    </div>
</li>

Notice the route value of the current page was appended to that last link. Somehow, the fact that the current page is /Reports/ChangeLogs/61, is causing the link in the menu to render with this route value!

I can't explain this. And I need to stop it from happening.

Further technical details

  • ASP.NET Core 3.1
  • Visual Studio 16.6.4 (Windows)
    .NET Core SDK (reflecting any global.json):
    Version: 3.1.302
    Commit: 41faccf259

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.302\

Host (useful for support):
Version: 3.1.6
Commit: 3acd9b0cd1

.NET Core SDKs installed:
3.1.302 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

@mkArtakMSFT mkArtakMSFT added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 31, 2020
@javiercn javiercn added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Jul 31, 2020
@mkArtakMSFT
Copy link
Contributor

Thanks for contacting us. @javiercn do we have a separate issue tracking this?

@ghost
Copy link

ghost commented Aug 4, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@SteveSandersonMS SteveSandersonMS added affected-most This issue impacts most of the customers bug This issue describes a behavior which is not expected - a bug. severity-minor This label is used by an internal tool labels Oct 7, 2020 — with ASP.NET Core Issue Ranking
@ghost
Copy link

ghost commented Oct 9, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Oct 12, 2022

Thanks for contacting us.
We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@MackinnonBuck
Copy link
Member

I was able to reproduce this behavior, but I'm not necessarily convinced it's a bug. Route values from the current request are reused in link generation (see https://learn.microsoft.com/aspnet/core/fundamentals/routing?view=aspnetcore-6.0#ambient-values-and-explicit-values), and I think that might apply to this case as well. You can override route values in the link by adding attributes to the <a> tag like asp-route-<name>="<value>" where 'name' and 'value' correspond to the name of the route value and its actual value respectively.

@javiercn Does my assessment seem correct that this is by design?

@SoftCircuits
Copy link
Author

@MackinnonBuck I always assumed it had been written to behave this way. I would argue that it makes no sense in this case though.

@MackinnonBuck
Copy link
Member

MackinnonBuck commented Nov 10, 2022

@SoftCircuits does the asp-route-{value} workaround address your needs?

@SoftCircuits
Copy link
Author

@MackinnonBuck I don't know what I would specify for {value}. I don't want any parameter passed. The parameter is optional on that page, and I don't want to specify any parameter here. I want the URL to just be /Reports/ChangeLogs.

This is from 2 1/2 years ago. I don't recall exactly how I worked around it.

@MackinnonBuck
Copy link
Member

@SoftCircuits if the /ChangeLogs/Index page has a route pattern defined like @page "{id?}", then you could change its corresponding <a> in _Layout.cshtml to:

<a class="dropdown-item" asp-area="Reports" asp-page="/ChangeLogs/Index" asp-route-id="">Change Logs</a>

This is from 2 1/2 years ago. I don't recall exactly how I worked around it.

That's fine! I'm going to close this issue as by-design for now, but we can reopen it if we get more feedback from the community that we should improve this behavior. Thanks!

@MackinnonBuck MackinnonBuck closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@MackinnonBuck MackinnonBuck added ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. and removed bug This issue describes a behavior which is not expected - a bug. labels Nov 10, 2022
@ghost ghost added the Status: Resolved label Nov 10, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-most This issue impacts most of the customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-routing ✔️ Resolution: By Design Resolved because the behavior in this issue is the intended design. severity-minor This label is used by an internal tool Status: Resolved
Projects
None yet
Development

No branches or pull requests

5 participants