I need to create a HttpGet method with two List parameters, but I'm getting this error:
has more than one parameter that was specified or inferred as bound from request body. Only one parameter per action may be bound from body. Inspect the following parameters, and use 'FromQueryAttribute' to specify bound from query, 'FromRouteAttribute' to specify bound from route, and 'FromBodyAttribute' for parameters to be bound from body:
MyObject
has two properties:
public class MyObject
{
public int Prop1 { get; set; }
public int Prop2 { get; set; }
}
Things I tried that throw exception above
Method 1
[HttpGet]
public IActionResult Get(List<MyObject> obj1, List<MyObject> obj2)
Method 2
[HttpGet]
[Route("{obj1}/{obj2")]
public IActionResult Get(List<MyObject> obj1, List<MyObject> obj2)
Method 3
[HttpGet("{obj1}/{obj2")]
public IActionResult Get(List<MyObject> obj1, List<MyObject> obj2)
Using FromQueryAttribute
I tried using:
[HttpGet]
public IActionResult Get([FromQueryAttribute] List<MyObject> obj1, [FromQueryAttribute] List<MyObject> obj2)
And it doesn't throw exception, but I don't know how to pass these parameters via query attribute?
Thanks in advance
p.s. I found How to pass multiple parameters to a get method in ASP.NET Core and Pass a list of complex object in query string to WEB API threads but didn't help me.