1
的API(C#编写的,ASP.NET核心)接收3个字段:标题,内容和类别的阵列(整数):发送阵列到API
[HttpGet]
[AllowAnonymous]
public IActionResult CreatePublication(string title, string content, IEnumerable<int> categoryIds)
{
return Ok();
}
问题是API总是接收categoryIds数组中的零个元素。
在Angular4客户端:
let ccategoryIds = new Array<number>()
ccategoryIds.push(2)
ccategoryIds.push(5)
ccategoryIds.push(7)
let requestOptions = {
params: new HttpParams()
.set('title', 'The title')
.append('content', 'The content')
.append('categoryIds', ccategoryIds.toString()),
withCredentials: true
}
this.http
.get('http://localhost:53203/api/publications/createPublication', requestOptions)
.subscribe(data => {
},
(err: HttpErrorResponse) => {
alert('Error')
})
更新
如果使用JSON.stringify(ccategoryIds)的代替ccategoryIds.toString(),收到在零个元素API也是。
@JohnDoe这看起来像是C#端的一个问题。我们能在那里看到你的代码吗? –