Home > Mobile >  FromQuery Is not working for nested types
FromQuery Is not working for nested types

Time:01-19

I have the following request object :

    public record SampleRequest
    {
        public int PageSize { get; set; }
        public int PageNumber { get; set; }
        public List<FilterModel> Filters { get; set; }
    }

    public record FilterModel
    {
        public string PropertyName { get; set; }
        public string PropertyValue { get; set; }
    }

And I'm trying to populate it from query for a HttpGet as following :

 [HttpGet]
 public IActionResult Get([FromQuery] SampleRequest request)
 {
       return Ok("");
 }

for testing I'm using SwaggerUI, but the binding it's not working for the Filter at all, it is always null. Any ideas?

CodePudding user response:

In this case swagger can not help you to test. Use postman like:

localhost:5001?PageSize=10&PageNumber=1&Filters[0].PropertyName=test&Filters[0].PropertyValue=somevalue&Filters[1].PropertyName=test&Filters[1].PropertyValue=somevalue

  •  Tags:  
  • Related