Home > Software design >  Route parameter Mvc Controller
Route parameter Mvc Controller

Time:04-14

I want to create a controller route to get details for an object with given id.

I know how to create a route like /data?id=15, but I would prefer the route to be /data/15. enter image description here

How do I do that?

Thanks in advance Paul

CodePudding user response:

[HttpGet]
[Route("data/{id}")]
public IActionResult Get([FromRoute(Name="id")] int id)
{
...
}
  • Related