0

I am pretty new in angularjs and I've looked around to try to find some posts on this and there are many but none that address my specific question (that I could find).

It is as simple as that, I want to send two parameters through angularjs ($http POST) where my first parameter is a json of class object and second is int. What I tried :

        var url = '../Request/'+ id;
        $http({
            method: 'POST',
            url: url,
            data: Data
        }).success(function (data, status, headers, config) {
            deferred.resolve(data);
        }).error(function (data, status, headers, config) {
            debug.error(data);
            deferred.reject('An error occured while saving the request');
        });

In my web api Controller I have :

    [POST("Request/{id}")]
    public bool SaveRequest(Data data, int id)
    {
       ...
       ...   
    }

When I send only Data it works for me but when I tried to add Id and Data both it won't work. Please let me know what needs to be done for the same, Thanks.

1 Answer 1

5

Have you tried using [FromBody] attribute like this

 [POST("Request/{id}")]
 public bool SaveRequest([FromBody] Data data,[FromUrl] int id)
 {
      ...

More info on parameter binding

0

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.