IFormFile always return null in asp.net core 2.1 IFormFile always return null in asp.net core 2.1 asp.net asp.net

IFormFile always return null in asp.net core 2.1


I've faced the same issue, I was able to fix it by applying the 'Name' named parameter to FromForm attribute with name of the File field in the form. It specifies which field in the form to bind to the method parameter. Change your method signature as shown here.

[HttpPost("status")]public async Task<BaseListResponse<MediaStorageModel>> MediaBrand([FromForm(Name ="file")] IFormFile file, int brandId)


Make sure the form is the correct enctype

<form asp-action="Edit" enctype="multipart/form-data">

I also had to change how the Model bind works from the generated code:

public async Task<IActionResult> Edit([Bind("Text,Example")] Example example)

to this code:

public async Task<IActionResult> Edit(Example example)