.NET Core : Areas attribute route value not passed correctly

104 views Asked by At

Area route link with parameter returns

`/admin/home/edituser/b36c7c26`

instead of

`/admin/home/edituser?id=b36c7c26`

This in turns scatters my interface, meanwhile am using the standard ASP.NET tag helper link generator

asp-action="edituser" asp-controller="home" asp-area="admin" asp-route-id="@user.Id"

Am I doing something wrong?

1

There are 1 answers

0
Moho On BEST ANSWER

The asp-route-{value} attribute enables a wildcard route prefix. Any value occupying the {value} placeholder is interpreted as a potential route parameter. If a default route isn't found, this route prefix is appended to the generated href attribute as a request parameter and value. Otherwise, it's substituted in the route template.

id is found in your route template so it is not appended as a request parameter and value. Your template is probably the typical default:

"{controller=Home}/{action=Index}/{id?}"

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-5.0