I want to post a list of object to .Net core web API from angular 9 application, Here i am using form-data because i need to post image with data and this is working for me but now a list of object property added to my view model. Here is my code example:
// ViewModel
public class ViewModel
{
public string Name { get; set; }
public IFormFile Image { get; set; }
public List<Connect> Connects { get; set; }
}
public class Connect
{
public string Name { get; set; }
public string Link { get; set; }
}
// .Net Core Action
[HttpPost]
public async Task<IActionResult> Post([FromForm] ViewModel vm)
{
}
// Angular component.ts
onSubmit() {
const formData = new FormData();
formData.append('name', this.model.name);
formData.append('image', this.form.get('image').value);
// Want add a list of object here to post with this
formData.append('connects', this.model.connects);
}