【发布时间】:2019-11-09 15:14:47
【问题描述】:
您好,我正在尝试将来自 angular6 的请求发布到 asp.net core web api,但不幸的是,该请求从未在服务器上收到,并且始终处于“待处理”状态。
我在服务器上的模型:
public class MainVM
{
public int ID { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public int DepartmentID { get; set; }
public IFormFile Logo { get; set; }
public List<ChildVM> ListChilds { get; set; }
}
public class ChildVM
{
public string Name { get; set; }
public int SequenceNo { get; set; }
public int NoOfPrices { get; set; }
public IFormFile Image { get; set; }
}
和终点:
[HttpPost]
[Consumes("multipart/form-data")]
public void Post([FromForm]MainVM data)
{
}
我用来从 Angular 发布数据的 Angular6 服务:
const formData: FormData = new FormData();
//formData.append('Logo', logo, logo.name);
formData.append('Name', obj.Name);
formData.append('ListChilds[0].Name', obj.ListChilds[0].Name);
formData.append('ListChilds[0].SequenceNo', String(obj.ListChilds[0].SequenceNo));
formData.append('ListChilds[0].NoOfPrices', String(obj.ListChilds[0].NoOfPrices));
return this.http.post<MainVM>('http://localhost:60458/api/mycontroller/', formData).pipe(
map((res) => { console.log('res'); return res; }),
catchError(this.handleError('lpc', null))
);
当我在 formData 中注释掉与 ListChilds 相关的代码时,请求在 web api 处收到,但请求未在带有 ListChilds 的 web api 处收到。
我想我错过了什么。
请指导。
谢谢。
【问题讨论】:
标签: c# asp.net-web-api angular6 asp.net-core-2.2