skip to Main Content

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

2

Answers


  1. 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);
    }
    
    
    Login or Signup to reply.
  2. 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);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search