0

I want to allow users of an API to send GET request that will run multiple queries on db and then return the result.

I have a query model like this

public class QueryModel 
{
   public int A {get;set;}
   public int B {get;set;}
   public int C {get;set;} 
}

I have a controller with a Get method like this -

public async Task<IActionResult> Get(List<QueryModel> queryModels)
{
   foreach(var queryModel in queryModels)
   {
      // some logic to search the db
   }
   // combine the results and return

}

This is not working for me, but I don't know if my query string is wrong or the method is wrong.

I have tried a number of variations of

?model={[{1,2,3},{1,2,3}]}

But they do not work.

1 Answer 1

1

You can use a construction like this:

\Get?model[0].A=1&model[0].B=2&model[0].C=3&model[1].A=4&model[1].B=5&model[1].C=6

Almost forgot, add FromUri:

public async Task<IActionResult> Get([FromUri] List<QueryModel> model)
{
 ...
}

Please let me know if this works for you.

Sign up to request clarification or add additional context in comments.

1 Comment

I just updated the question. I want to perform multiple queries on a db with a single GET request.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.