Web api passing array of integers to action method

后端 未结 4 390
滥情空心
滥情空心 2021-01-16 08:28

I have this web api method:

[HttpGet]
[Route(\"WorkPlanList/{clientsId}/{date:datetime}\")]
public async Task

        
4条回答
  •  生来不讨喜
    2021-01-16 09:03

    Custom model binding is one option. But easier would be to pass the values in the request body rather than in the URI.

    As best practice, complex data should not be present in the URI. So workaround in your case would be to :

    1. create a JSON array and include it in the request body.

    2. write [FromBody] before List clientsId, which will force the framework to retrieve the data from request body. Model binding will happen automatically.

提交回复
热议问题