Home > Enterprise >  How to send array to HttpPost from Angular to .Net Framework(ApiController)?
How to send array to HttpPost from Angular to .Net Framework(ApiController)?

Time:12-24

I trying to send Angular array data to .Net Framework server side

My current code looks like:

Angular: code below

service.ts

   addRecipient(val:any)
    {
      return this.http.post(this.APIUrl '/recipient',val);
    }

recipient.ts

SendSurveyList: any = []; - declared list

this.SendSurveyList.push(val); - pushing results

Sending results via server: ->

  this.service.addRecipient(this.SendSurveyList).subscribe(res=>
        {
          alert(res.toString()   "Was Sent");
        });

.Net Framework: code below

 // POST api/values
        [HttpPost]
        public HttpResponseMessage Post([FromBody]Recipient postRecipient)
        {
        }
  1. Current Result: HttpPost returning null;
  2. Expecting result: HttPost returning SendSurveyList list data.

My idea:

I have an idea to change service.ts side post url to like:

 addRecipient():Observable<any[]>
    {
      return this.http.post(this.APIUrl '/recipients');
    }

But this is valid only for http.GET side ~ I don't actually know how to realize it from http.Post.

I am also looking forward to your ideas. Since I managed to implement Post for a single record. But I would like to do it for List / Array data throug.

CodePudding user response:

// POST api/values
        [HttpPost]
        public HttpResponseMessage Post([FromBody]List<Recipient> listPostRecipient)
        {
        }
  • Related