How to use FromQueryAttribute get a complex object?
[HttpGet]
public IActionResult Get([FromQuery] DataGridRequest request)
{
...
}
The DataGridRequest class like this:
public class DataGridRequest
{
public DataGridPager Pager { get; set; }
...
}
public class DataGridPager
{
public int Size { get; set; }
public int Index { get; set; }
}
How to write the uri?
2 Answers
You can try a Get request like this
controller?Size=1&Index=2
Also try to use [FromUri] instead [FromQuery]. The [FromUri] attribute tries to bind the object properties to the query string properties by name
Do this to set data for subobjects using [FromQuery]:
controller?Pager.Size=1&Pager.Index=2