dotnet / dotnet/aspnetcore

IFormFile binding error

Open
#28,273 8 comments 4 reactions 0 assignees View on GitHub
area-mvc feature-model-binding investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Describe the bug
I have a model with IFormFIle property and other simple type properties.It could pass to the controller with [ApiController] and [FromForm] successfully.But If I only pass IFormFile property in model,it could not pass data to controller.I find a solution,when I remove [ApiController] and [FromForm],it works.
### To Reproduce

using asp.net core 3.1

Model:
```
public class ProductImageDetailsDto
{
public IFormFile ProductImage { get; set; }

public bool IsDefaultImage { get; set; }

}
```

Controller:
```
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
[HttpPut("UpdateProductImagesByProductId/{id}")]
public async Task UpdateProdutImagesByProductId(Guid id,[FromForm]List productImages)
{

return Ok();
}
}
```

SO Reference:

https://stackoverflow.com/questions/65085522/how-to-upload-multiple-files-using-multipart-form-data-media-type-in-net-core-w/65087114

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.