在 .net core 3.1 returns 中使用 [FromRoute] 和 [FromQuery] 与对象绑定模型 returns null

Model binding with objects using [FromRoute] and [FromQuery] in .net core 3.1 returns null

我试图在邮递员中使用这个 url 来点击操作方法,但它没有读取值 来自 [FromRoute] 的 employeeNumber 邮递员请求:https://localhost:44309/Department/9002069554

[HttpGet("{employeeNumber}", Name = "Get")]  
public async Task<IActionResult> Get([FromRoute] Employee employeeNumber)
    {
        //
    }
public class Employee
{
    [BindRequired]
    [FromRoute]
    public string employeeNumber { get; set; }
}

接受参数不能与属性名称相同,您应该更改它。

[HttpGet("{employeeNumber}", Name = "Get")]  
public async Task<IActionResult> Get([FromRoute] Employee employee)
{
    //
}