Skip to content

AddRazorPages/MapRazorPages breaks generated link by asp-route-* tag helpers to MVC controller route. #25299

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
marlongerson opened this issue Aug 27, 2020 · 3 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-routing Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.

Comments

@marlongerson
Copy link
Contributor

marlongerson commented Aug 27, 2020

Describe the bug

I have scaffolded default identity pages into my MVC project, so I have a mix of razor pages and MVC views. However, AddRazorPages and MapRazorPages are breaking one of my links generated by the asp-route-* tag helpers to one of my controller action methods.

I have an action method that looks like the following:

[HttpGet("symbols/{symbol}/{slug}/news")]
public IActionResult News(
    [FromRoute] string symbol,
    [FromRoute] string slug,
    [FromQuery] int perPage,
    [FromQuery] int page)
{
    return View();
}

When I generate the link in my view (without AddRazorPages/MapRazorPages), the link is generated correctly. For example, the following will generate the correct url as symbols/aapl/apple-inc/news?page=2&perPage=20.

<a asp-action="News"
   asp-controller="Symbols"
   asp-route-symbol="aapl"
   asp-route-slug="apple-inc"
   asp-route-page="2"
   asp-route-perPage="20">
    Page 2
</a>

However, that same code with AddRazorPages/MapRazorPages in Startup.cs breaks the way that link is generated, and is rendered incorrectly as the following: symbols/news?symbol=aapl&slug=aapl-inc&page=11&perPage=5. The symbol and slug parameters are incorrectly rendered as part of the query, when they should be part of the route.

To Reproduce

Link to repo to reproduce error: https://github.com/marlongerson/IncorrectRouting.

Step 1. With lines 28 and 57 in startup.cs commented out: Run the project. From home page, click on "Go to apple news", and notice that the pagination links are correct.
Step 2. Uncomment lines 28 and 57. Run the project. From home page, click on "Go to apple news", and notice that the pagination links break with AddRazorPages and MapRazorPages.

Exceptions (if any)

Further technical details

  • ASP.NET Core version: 3.1
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version: Rider 2020.1.0 on Windows

Output of dotnet --info

.NET Core SDK (reflecting any global.json):
Version: 3.1.400
Commit: 035fb2aa2f

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

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

.NET Core SDKs installed:
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.100-preview7-012821 [C:\Program Files\dotnet\sdk]
3.0.103 [C:\Program Files\dotnet\sdk]
3.1.100 [C:\Program Files\dotnet\sdk]
3.1.400 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotne
t\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotne
t\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotne
t\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotne
t\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview7.19365.7 [C:\Pro
gram Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.3 [C:\Program Files\dotnet
\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [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.8 [C:\Program Files\dotnet\sh
ared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\sh
ared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\s
hared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\s
hared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\sh
ared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview7-27912-14 [C:\Progr
am Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.3 [C:\Program Files\dotnet\sh
ared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\sh
ared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\sh
ared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview7-27912-14 [C
:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.Ap
p]
Microsoft.WindowsDesktop.App 3.0.3 [C:\Program Files\do
tnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\do
tnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\do
tnet\shared\Microsoft.WindowsDesktop.App]

@marlongerson marlongerson changed the title AddRazorPages/MapRazorPages breaks MVC controller route. AddRazorPages/MapRazorPages breaks generated link by asp-route-* tag helpers to MVC controller route. Aug 27, 2020
@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 27, 2020
@javiercn
Copy link
Member

@marlongerson thanks for contacting us.

If you are explicit about the area and set it to asp-area="" in your page, does that fix the issue?

@mkArtakMSFT mkArtakMSFT added feature-routing Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Aug 27, 2020
@marlongerson
Copy link
Contributor Author

marlongerson commented Aug 27, 2020

@javiercn I just tried with asp-area="". It doesn't fix it, same erroneous link.

I just discovered that this issue may be related to having page as a parameter and having the asp-route-page tag helper. When I comment that out in the anchor tag the link is generated correctly. Might be related to this issue aspnet/Mvc#6660

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Aug 27, 2020
@javiercn
Copy link
Member

@marlongerson that's likely it, I missed that when I looked at the sample.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-routing Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.
Projects
None yet
Development

No branches or pull requests

3 participants