0

i have a Model in web api

  public class myModel{
public string FirstName{get;set;}
public string LastName{get;set;}
public int Age {get;set;}
}

Web api Controller

public string saveRecord(myModel data){

return data;
}

angular post ....

  function(){
    var obj={
    FirstName:'Robin',
    Age:24
    }

$http.post(myurl,{ obj}).then(function(rp){
alert(rp.data);
}


}

i have passed only two parameter in post.
now i am getting all values is null in response

1 Answer 1

0

Try to create a new object and config the headers:

$http.defaults.headers.post["Content-Type"] = "application/json";  

var myModel = new obj();
myModel.FirstName = "Robin";
myModel.Age = 24;

$http.post(myurl, JSON.stringify(myModel));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.