I need to send image list and product data to ASP.net api via formData. I succesfully sended images but now i dont really know how to append whole object. I have seen some ways to do that in JS JSON.stringfy(object)
or Object.keys(object).forEach(key => formData.append(key, object[key]));
but it doesnt works for me.
- Angular http服务 *
updateProduct(imageProductVM:ProductImageViewmodel): Observable<any> {
const formData = new FormData()
// imageProductVM.product ??
for (const photo of imageProductVM.files) {
console.log(photo)
formData.append('files', photo)
}
return this.http.post(this.apiURL + '/product/', formData, {headers:{"ContentType": "multipart/form-data"}})
}
- ASP.NET应用程序接口 *
x一个一个一个一个x一个一个二个x
1条答案
按热度按时间ki0zmccv1#
事实上,我忘了说我的产品对象也有嵌套对象。谢谢widoss分享这些信息。
This answer helped me to understand what an object should look like for ASP.net , Here's how it should look in my case:
然后我使用以下代码将对象转换为兼容视图:
我希望这能帮到一些人