【发布时间】:2020-08-14 09:03:03
【问题描述】:
我想从 Angular 9 应用程序向 .Net 核心 Web API 发布对象列表,这里我使用表单数据,因为我需要发布带有数据的图像,这对我有用,但现在是对象属性列表添加到我的视图模型中。这是我的代码示例:
// 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);
}
【问题讨论】: