I want to upload multiple files and used IFormFile to upload file using asp.net core 5 but the problem is it shows me string data type instead of the IFormFile. Can I just override the field attachment: "string" property to File object? See details below:
Sample json data
id: 1122,
name: "yourname",
address: "your complete address",
attachments: [{
"Id": 0,
"Name": "string",
"attachment": "string" // file attachment, I expect to be form upload button or similar
}] // please do note that this will have maximum of 5 arrays
// can attachment: string json property can be override with File object?
Main Model
public class MainModel
{
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
[MaxLength(10)]
public List<Attachment> Attachments { get; set; }
}
Attachment Model
public class Attachment
{
[Required]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
[DataType(DataType.Upload)]
public IFormFile Attachment { get; set; } // this is weird, instead of upload file it shows string instead.
}
Main Controller
[HttpPut("main/update")]
public IActionResult UpdateMain([FromForm] MainModel model)
{
if(ModelState.IsValid)
{
var result = _test.UpdateMain(model);
return Ok(new { data = result });
}
return BadRequest();
}
I don't know why it has a string DataType into and it doesn't make sense for me.
The data being sent to the web api is a File object which it doesn't make sense. Can someone help out in this one?

IdandNamein yourAttachmentsI mean where they come from when you have not uploaded anything?Fileobject?