【发布时间】:2019-05-15 06:38:06
【问题描述】:
所以我期待的是,当 Angular 6 应用程序使用 GET 方法请求时,将唯一标识符的列表或数组作为参数发送到 ASP.NET Core Web API,然后 ASP.NET Core 将带来仅与将唯一标识符数组返回到 Angular 应用程序。
我的 Web API 代码看起来像这样。
[HttpGet]
public ActionResult GetByGuids(List<Guid> Guids)
{
// some code here...
return Ok(_someService.someAction(Guids));
//Guids will be passed as a parameter to the function of service layer
}
根据我自己的研究,我无法将唯一标识符数组添加到正文中,因为这是 GET 方法。
我必须添加 [FromQuery],因为如果我在参数是数组或列表时不添加它会产生错误。
如果 [FromQuery] 是处理这种情况的唯一方法,那么我不知道应该如何为 Angular 编写代码。
请帮忙。
提前谢谢你。
【问题讨论】:
-
更改为
IEnumerable<Guid> Guids并传递为?Guids=6d627994-dce5-487e-bd2c-d48c0311a2e0&Guids=29a76d51-3c44-4fde-a0f1-b1f34567175e等? -
“因为如果我不添加它会产生错误” - 请确保在遇到错误时包含错误消息。
标签: c# angular typescript asp.net-core asp.net-core-webapi