PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 19, 2022

[FIXED] How to send array to HttpPost from Angular to .Net Framework(ApiController)?

 May 19, 2022     .net, angular, asp.net, typescript, web-services     No comments   

Issue

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.


Solution

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


Answered By - user2763884
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing