0

I have this angular js code here:

$http.post('/reports/', JSON.stringify($scope.user));

and its hitting my Reports Controller Post method:

[HttpPost]
public dynamic Post(Array data){
  //do something
}

but when I check the data in my Post method when it hits in my breakpoint it appears as null :( how do I pass the data from $scope.user to my Controller. I did a console.log of $scope.user and the data is there, it is an object but trying to pass it in as JSON.

I found this:

public HttpResponseMessage Post([FromBody]Customer cust)
        {
            var newCust = _Repository.InsertCustomer(cust);
            if (newCust != null)
            {
                var msg = new HttpResponseMessage(HttpStatusCode.Created);
                msg.Headers.Location = new Uri(Request.RequestUri + newCust.ID.ToString());
                return msg;
            }
            throw new HttpResponseException(HttpStatusCode.Conflict);
        }

would I have to put [FromBody] Reports report instead of Array data

1 Answer 1

1

Just do this simple as possible, you are missing the parameter name:

$http.post('/reports/', {data: $scope.user});

Make sure that $scope.user is an Array, else change the type.

Sign up to request clarification or add additional context in comments.

2 Comments

Array is just something I put in there for now, I am looking to pass in JSON data to my .NET API Controller
The controller will bind the object to It correspondent at the parameter. Just pass the write thing.

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.