Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer
    
nope, trying if work, will get back to you –  Haseeb Akhtar Nov 22 '13 at 6:09
    
Thanks, it works for me –  Haseeb Akhtar Nov 22 '13 at 7:14

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.