【发布时间】:2018-04-27 15:53:27
【问题描述】:
我正在使用 aurelia-fetch-client 向 ASP.NET Core Web 应用程序发送一组 Guid,但是在服务器端,模型绑定器没有接收到它,notificationIds 的列表是 @987654326 @。但是,当我通过 Swagger 或 CURL 发出请求时,它绑定得很好。
我更改了我的控制器方法的签名以接受字符串列表,以防 GUID 格式出现问题,但同样的问题。
JS
var body = {notificationIds : this.notifications.map(x => x.notificationId) };
console.log("Dismissing All notifications");
await this.httpClient.fetch('http://localhost:5000/api/notifications/clear',
{
method: 'POST',
body: json(body),
headers: {
'Authorization': `Bearer ${localStorage.getItem('access_token')}`,
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Requested-With': 'Fetch'
},
mode: 'cors'
}).then(response => {
if(response.status == 204){
//Success! Remove Notifications from VM
}
else{
console.log(response.status)
}
})
控制器方法
// POST: api/Notifications
[HttpPost]
[Route("clear")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<IActionResult> Post([FromBody]List<string> notificationIds)
{
if (notificationIds.IsNullOrEmpty())
{
return BadRequest("No notifications requested to be cleared");
}
var name = User.Claims.ElementAt(1);
await _notificationRepository.Acknowledge(notificationIds, name.Value);
return NoContent();
}
但是提琴手可以
【问题讨论】:
-
据我所知,您没有将返回的数据设置为 VM 上的任何属性。
-
我不想在虚拟机上设置任何东西。事实是,当我发布 guid 列表时,服务器上的模型绑定器没有拾取它们,这就是问题
-
啊。我完全误解了这个问题。对此感到抱歉。
-
没问题....:)
-
看到这很有趣。 Chrome 没有显示任何已发布的内容,但 fiddler 会显示......
标签: asp.net asp.net-core asp.net-core-mvc aurelia