0

I tried to make a post request from ionic to web api this way

ionic code

$http({
              url: 'http://localhost:1449/api/IonicApi',
              method: "POST",
              data: {
            firstName : "a",
            lastName : "b",
            email : "ab@ab.com"
          },
              headers: { 'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8" }
          }).then(function (response) {
              // success
              $ionicPopup.alert({
                title: 'Your Name is '+$scope.man.firstName + ' '+$scope.man.lastName,
                template: 'It might taste good'
            })
          }, function (response) { // optional
              // failed
              console.log('failed');

          });

and the c# part is

 public IHttpActionResult Post(tblPerson person)
        {
            db = new MobileDBEntities();
            db.tblPersons.Add(person);
            db.SaveChanges();
            return Ok();

I tried from postman to post data it was working. But from Ionic it is passing null data of object enter image description here

What wrong did I make here?

Postman screenshot I am adding here enter image description here

Newaz Sharif
  • 424
  • 4
  • 12

1 Answers1

0

Is it possible to call you api like below where obj is your data

$http.post('http://localhost:1449/api/IonicApi',obj).success(function(){

}).error(function()
{
});
Arun
  • 450
  • 3
  • 8