Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48986

Post method: value from budy is null in API

$
0
0

I developped a post methode in API (coded on ASP.NET)

  // POST api/<controller>
        public string Post([FromBody]string id) //add user
        {
            using (BDPLMProjectENEntities db = new BDPLMProjectENEntities())
            {
                membre mem = db.membres.Where(model => model.IDmembre == id).FirstOrDefault();
                usersProject usr = db.usersProjects.Where(model => model.IDressource == id).FirstOrDefault<usersProject>();
                if (usr == null)
                {
                    
                    ajouterUtilisateur(mem, true);
                    return "user added";
                    
                }
                else
                {
                    return "This member already belongs to users." ;
                }

            }
        }

This is post method in rest.service.ts from Ionic app:

addUser(id){
  
  let body = {"id":id};   
 console.log(body);    
return this.http.post(this.apiUrl +'/Resource',JSON.stringify(body),this.httpOptions).map(res=>res.toString());      

}

and this is where I call the post method from users.page.ts

 let alert = await this.alertCtrl.create({
        header : 'Choose one',
        inputs : radio_options ,
        buttons: [
          {
            text: 'Cancel',
            role: 'cancel',
            handler: () => {
              console.log('Cancel clicked');
            }
          },
          {
            text: 'Ok',
            handler: data => {//data: id user
             this.iduser=data;
             console.log( this.iduser);
           this.api.addUser(this.iduser).subscribe( data=>{ //data from api=result of add user
            console.log(data)
            });
          }
          }
        ]
    });
    
  await alert.present();

the problem is when I test in the API I get the id is null however I put the right id and you can see it in the console.log in rest.service.ts and users.page.ts

image

This is from visual studio (web API)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48986

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>