Search code examples
c#asp.net-core-webapiasp.net-core-routing

How to concatenate route strings from [Route] and CRUD operation headers


I would like to concatenate the route specified in my [Route()] header with the routes in my [HttpPost()], [HttpGet()], [HttpPut()] and [HttpDelete()] headers.

I tried researching.

[Route("api/[controller]")]
[ApiController]
public class AdminController : ControllerBase
{
    [HttpGet("/user/add/{num1}/")]
    public IActionResult SumActionResult(int num1)
    {
        return Ok(num1 );
    }
}

I would like to be able to call the SumActionResult method by using the following uri: `

localhost/api/admin/user/add/input

Solution

  • I suppose you shoud replace [HttpGet("/user/add/{num1}/")] with [HttpGet("user/add/{num1}")]