[SOLVED] asp-route-id always pass id as query parmeter

Issue

I’m trying pass id as route parameter by asp-route-id always pass as a query parameter
and I don’t want to use href

<a asp-area="Employe" asp-controller="PersonManager" asp-action="UserDetails" asp-route-id="@Model.Provider.Id">details</a>

the route is like this

https://localhost:5002/Employe/PersonManager/UserDetails?id=b4065ff6-c7bd-4244-a6b6-9bc6b7b4c7a8

but I want be like this

https://localhost:5002/Employe/PersonManager/UserDetails/b4065ff6-c7bd-4244-a6b6-9bc6b7b4c7a8

and this is my action

[HttpGet]
    public async Task<IActionResult> UserDetails([FromRoute] Guid id)
    {
        var user = await _service.GetOneUser(id);

        return View(user);
    }

and I don’t want change fromRoute to fromQuery it must be FromRoute

Solution

To use the Id as part of the route, you need to define it as part of the HttpGet attribute.

[HttpGet("UserDetails/{id}")]
public async Task<IActionResult> UserDetails([FromRoute] Guid id)
{
    var user = await _service.GetOneUser(id);
    return View(user);
}

Answered By – Anuraj

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *