Home > Mobile >  asp-route-id always pass id as query parmeter
asp-route-id always pass id as query parmeter

Time:03-06

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

CodePudding user response:

Define the route for HttpGet:

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

    return View(user);
}

CodePudding user response:

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);
}
  • Related