所以我期待的是,當 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 編寫代碼。請幫忙。
1 回答

Smart貓小萌
TA貢獻1911條經驗 獲得超7個贊
更改List<Guid> Guids
為[FromQuery]List<Guid> Guids
:
public ActionResult GetByGuids([FromQuery]List<Guid> Guids)
然后,您可以將請求作為http://myserver/controller/GetByGuids?Guids=6d627994-dce5-487e-bd2c-d48c0311a2e0&Guids=29a76d51-3c44-4fde-a0f1-b1f34567175e
- 1 回答
- 0 關注
- 151 瀏覽
添加回答
舉報
0/150
提交
取消