为什么这条路线不起作用?

Why does this route not work?

在 class 我有:

[Route("api/candidate/free")]

关于方法,我有:

[HttpDelete("{dateRangeId}")]
public IActionResult Delete(int dateRangeId)

这会导致 404:

/api/candidate/free/123

删除属性时:

[HttpDelete]
public IActionResult Delete()

这不会导致 404:

/api/candidate/free/

参数有什么问题?

路由约束区分大小写。你有 Int 而它应该是 int

该操作还应遵循带有约束的预期路由模板以匹配请求,否则您将得到 404(未找到)

[Route("api/candidate/free")]
public class MyController : Controller {

    //...

    //DELETE api/candidate/free/123
    [HttpDelete("{dateRangeId:int}")]
    public IActionResult MyAction(int dateRangeId) {

        //...

        return Ok();
    }

}

引用Routing to Controller Actions

引用Routing in ASP.NET Core

这对我来说...

[HttpPost("delete")]
public IActionResult Delete([FromQuery] int dateRangeId)