У меня проблема с привязкой модели с использованием атрибутов [FromQuery].
У меня есть следующие классы:
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);
}
}
Запрос:
public class GetBlogListQuery : IRequest<IExecutionResult>
{
public string Filter { get; set; }
public PaginationSettings PaginationSettings { get; set; }
}
и, наконец,Метод контроллера:
[HttpGet]
[ProducesResponseType(200)]
[ProducesResponseType(204)]
public async Task<IActionResult> GetBlogs([FromQuery] GetBlogListQuery query)
{
...
}
Если я пытаюсь вызвать Get по следующему URL, я получаю HTTP 500.
http://localhost:5000/api/Blogs/GetBlogs?PaginationSettings.RecordsPerPage=2&PaginationSettings.PageIndex=2