Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am creating a Single Page Application using ASP.NET Web API and AngularJS. The problem is that when I post data from AngularJS controller to API controller, the object is getting passed but all the values of different properties are not those which were assigned but default values.

Model is defined as follows:

 public class Expense
{
    [Key]
    public int ID { get; set; }
    public string Description { get; set; }
    public int Amount { get; set; }
}

This is the value of object which I passed from AngularJS controller, which I see in the AngularJS JavaScript file breakpoint,

"{"ID":1,"Description":"test","Amount":1000}"

 $http.post("/Expenses/Create",  $scope.expense);

And this is what it reaches to the controller:

    [HttpPost]        
    [ActionName("Create")]
    public IActionResult Create(Expense expenses)`

{"ID":0,"Description":null,"Amount":0}"
share|improve this question
    
this probably means that the data is not correctly formatted, your request reaches the server but with no data or invalid data – gaurav5430 Jan 14 at 5:00
    
what can be done to correctly format the data? – Developer Jan 14 at 5:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.