【发布时间】:2019-12-03 09:13:41
【问题描述】:
我想将对象内的整数列表发送到 C# 中的 POST API。这就是我正在做的事情:
const headers = new HttpHeaders().append(
"Content-Disposition",
"multipart/form-data"
);
let formData: FormData = new FormData();
formData.append("name", "name");
formData.append("Ids", JSON.stringify(Ids));
return this._http.post(
`${environment.baseUrl}${this.companyApiUrl}`,
formData,
{ headers: headers }
);
其中Ids 的类型为number[]。
以下是 C# WebAPI:
public ActionResult<MyModel> Post([FromForm] MyModel model)
{
...
}
MyModel:
public class MyModel
{
public string Name { get; set; }
public List<int> Ids { get; set; } // I have also tried int[]
}
我从 Web API 收到以下错误:
{"Ids":["值 '[5,6,7]' 无效。"]}
我如何实现这一目标?我想将MyModel 中Ids 的类型保留为List<int> 或int[](直接发送ID,而不在服务器中解析JSON)。
【问题讨论】:
标签: c# asp.net angular asp.net-core