I have an issue with model binder for bind a list of object in a multipart/form-data request to related C# class property.
This is my request in Swagger:
And in my action method, the ProductAttributes count is 0:
But I expect the count to be 2.
I also test the post request with Postman:
but the result is the same.
CreateProductDto class:
public class CreateProductDto
{
public string Name { get; set; }
public string Description { get; set; }
public int QIS { get; set; }
public decimal Price { get; set; }
public float DiscountPercentage { get; set; }
public int CategoryId { get; set; }
public List<IFormFile> Images { get; set; }
public List<ProductAttributeCreateDto> ProductAttributes { get; set; }
}
ProductAttributeCreateDto class:
public class ProductAttributeCreateDto
{
public int AttributeId { get; set; }
public string Value { get; set; }
}
CreateProduct action method:
[HttpPost("CreateProduct")]
public async Task<ActionResult> CreateProduct([FromForm]CreateProductDto createProductDto)
{
// ...
}


ProductAttributesin Postman is incorrect. It should be:ProductAttributes.0.attributeId: 5,ProductAttributes.0.value: string. It is flatten JSON notation.[FromBody]jsons, or you'd need some workarounds.