Jen
Jen

Reputation: 87

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

I have tried to hit the action method with this url in the postman and it's not reading the value for employeeNumber from [FromRoute] Postman request: 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; }
}

Upvotes: 0

Views: 835

Answers (1)

mj1313
mj1313

Reputation: 8469

The accept parameter can't be same as the property name, you should change it.

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

Upvotes: 1

Related Questions