I have the following controller's action:
[HttpPost("api/v1/addProduct")]
[Consumes("multipart/form-data")]
public Task<ProductDto?> AddProduct([FromForm] ProductRequest request, CancellationToken cancellationToken)
{
return _productService.AddProduct(request, cancellationToken);
}
and the following model:
public class ProductRequest
{
[Required]
public string Title { get; set; }
public string? Description { get; set; }
[Required]
public string PreviewDescription { get; set; }
[Required]
public IFormFile PreviewImage { get; set; }
public IFormFile[]? Images { get; set; }
[Required]
public int[] CategoryIds { get; set; }
public bool? IsAvailable { get; set; }
}
I successfully sent data to the server (I use formData):
But by some reason, I see the following in the debugger:
Everything is ok with previewImage but where are images? Why previewImage is here, but there is no images? I sent them in exactly the same way as I sent previewImage. We can see it at the request payload screen. Help me please to figure it out.
UPDATE
I tried IFormFileCollection:
No result.
But:
As we can see here (using HttpContext.Request.Form.Files) I see all the files. What is wrong with binding?
I can solve it in this way:
But it looks awful. Model binding must work here! Why it doesn't?





Ok I found the solution. I used wrong name for
images. I have to useimagesinstead ofimages[]:This is a bit strange, because as you can see I have
categoryIds[]it is an array, and it works as expected.Now I see: