I'm trying to post FormData
including both a File
and a Collection
.
This is my Model:
public class Content
{
public string Name { get; set; }
public string Link { get; set; }
}
public class Model
{
public IEnumerable<Content> Contents { get; set; }
public IFormFile File { get; set; }
}
This is my action:
[HttpPost]
public async Task InsertAsync([FromForm]Model dataPost)
{
await _services.Create(dataPost);
}
My FormData
in JavaScript is:
const formData = new FormData();
formData.append("File", myFile, "image.jpg")
formData.append("Contents", arrayOfContent)
And here is the header
:
'Content-Type': `multipart/form-data`
The "File" is working fine, but the "Content" is always null.
Where am I going wrong? Thank you!