Skip to content
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

Improve MapGroup link generation test #44562

Merged
merged 2 commits into from
Oct 18, 2022
Merged

Improve MapGroup link generation test #44562

merged 2 commits into from
Oct 18, 2022

Conversation

halter73
Copy link
Member

Turns out you need to call MapControllerRoute instead of MapControllers for the endpoint-routing-based link generation to work. I was also missing asp-route-org="contoso" in the razor page.

Fixes #41430

@JamesNK
Copy link
Member

JamesNK commented Oct 15, 2022

Turns out you need to call MapControllerRoute instead of MapControllers for the endpoint-routing-based link generation to work.

If a controller doesn't have attributes on it, then a controller route needs to be specified with the map controller call.

Is there a test for a controller with attributes?

@halter73
Copy link
Member Author

Is there a test for a controller with attributes?

No. I tried to add one as follows (without any groups first this time):

<a id="route-attribute-link" asp-action="Get" asp-controller="EndpointRoutingController" asp-route-id="10">Test</a>

But it generates a link to /EndpointRoutingController/Get/10 instead of /endpoint-routing/10 like expected. It appears to just be going with the MapCotrollerRoute pattern rather than using the [Route] attributes as it should, so the generated link 404s. Do you know why that happens?

@JamesNK
Copy link
Member

JamesNK commented Oct 18, 2022

I don't know exactly why. My guess is the controller has two routes, and MapCotrollerRoute is taking precedence, so the link generator is going with it.

I recommend using MapControllers with the attribute route test. Mixing the two together (convention routes and attribute routes) is a weird thing to do.

@halter73 halter73 merged commit 5e42cca into main Oct 18, 2022
@halter73 halter73 deleted the halter73/41430 branch October 18, 2022 19:47
@ghost ghost added this to the 8.0-preview1 milestone Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Route Groups] Investigate link generation bug
3 participants