Passing multiple parameters to web API GET method

前端 未结 1 385
予麋鹿
予麋鹿 2020-12-12 06:39

I have created a WEB API using MySQL Database. The API works as expected for now. I sent a meter serial number and a date time parameter and then G

相关标签:
1条回答
  • 2020-12-12 07:08

    You can pass a custom model to an action method, but I suggest not using the GET for you task because GET does not have a body.

    Instead, use the SEARCH verb and put the list of serials number and the date inside a custom model in the body.

    public class MeterSearchModel 
    {
       public List<string> Serials {get;set;}
       public DateTime Date {get;set;}  
    }
    

    In .NET Core 2 your controller would have something like -

    [AcceptVerbs("SEARCH")]
    public async Task<IActionResult> Search([FromBody] MeterSearchModel model)
    {
        //..perform search 
    }
    
    0 讨论(0)
提交回复
热议问题