我試圖將 Angular 陣列資料發送到 .Net Framework 服務器端
我當前的代碼如下所示:
角度:下面的代碼
服務.ts
addRecipient(val:any)
{
return this.http.post(this.APIUrl '/recipient',val);
}
收件人.ts
SendSurveyList: any = [];-宣告串列
this.SendSurveyList.push(val); - 推動結果
通過服務器發送結果: ->
this.service.addRecipient(this.SendSurveyList).subscribe(res=>
{
alert(res.toString() "Was Sent");
});
.Net 框架:下面的代碼
// POST api/values
[HttpPost]
public HttpResponseMessage Post([FromBody]Recipient postRecipient)
{
}
- 當前結果:HttpPost 回傳 null;
- 預期結果:HttPost 回傳 SendSurveyList 串列資料。
我的點子:
我有一個想法,將 service.ts 側帖子 url 更改為喜歡:
addRecipient():Observable<any[]>
{
return this.http.post(this.APIUrl '/recipients');
}
但這僅對 http.GET 方有效~我實際上不知道如何從 http.Post 中實作它。
我也很期待你的想法。因為我設法為單個記錄實作了 Post。但我想通過串列/陣列資料來做。
uj5u.com熱心網友回復:
// POST api/values
[HttpPost]
public HttpResponseMessage Post([FromBody]List<Recipient> listPostRecipient)
{
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/391699.html
