【发布时间】:2021-08-19 01:15:57
【问题描述】:
我有一个问题,我需要将模型作为第一个参数传递,作为第二个参数,我需要传递一个文件
将文件添加到表单:
const formDate = new FormData();
formDate.append("File", this.file);
从角度发送数据:
this.dataService.createRestaurant(this.restaurant, formDate)
.subscribe((data: Restaurant) => this.loadProducts(data))
数据发送服务:
createRestaurant(model: Restaurant, form: FormData){
const headers = new HttpHeaders().append("Content-Disposition", "multipart/form-data")
return this.http.post(this.url, {model, form}, {headers: headers});
}
Asp.net 核心中的控制器:
public IActionResult Post(Restaurant restaurant, IFormFile File)
{
code...
}
我试了两天解决这个问题,模型传输正常,但是文件总是为空
【问题讨论】:
标签: c# angular asp.net-core asp.net-core-webapi