如何连接来自 [Route] 的路由字符串和 CRUD 操作 headers

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

我想将 [Route()] header 中指定的路由与 [HttpPost()][HttpGet()][HttpPut()][HttpDelete()] headers.

我试着研究了一下。

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

我希望能够使用以下 uri 调用 SumActionResult 方法:`

localhost/api/admin/user/add/input

我想你应该用 [HttpGet("user/add/{num1}")]

替换 [HttpGet("/user/add/{num1}/")]