I have a problem with model binding using [FromQuery] attributes.
I have the followings classes:
public class PaginationSettings
{
public const int DefaultRecordsPerPage = 5;
public PaginationSettings(int pageIndex, int recordsPerPage)
{
RecordsPerPage = recordsPerPage == 0 ? DefaultRecordsPerPage : recordsPerPage;
PageIndex = pageIndex == 0 ? 1 : pageIndex;
}
public int RecordsPerPage { get; set; }
public int PageIndex { get; set; }
public int RecordsStartIndex => RecordsPerPage * (PageIndex - 1);
public static PaginationSettings Normalize(PaginationSettings source)
{
if (source == null)
{
return new PaginationSettings(0, 0);
}
return new PaginationSettings(source.PageIndex, source.RecordsPerPage);
}
}
Query:
public class GetBlogListQuery : IRequest<IExecutionResult>
{
public string Filter { get; set; }
public PaginationSettings PaginationSettings { get; set; }
}
and finally Controller method:
[HttpGet]
[ProducesResponseType(200)]
[ProducesResponseType(204)]
public async Task<IActionResult> GetBlogs([FromQuery] GetBlogListQuery query)
{
...
}
If I try to call Get with the following URL I get HTTP 500.