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 try to pass an array of object from angular to mvc webapi via post method but with no success.

This is my client code:

    $http({
        url: '/api/messages/graph',
        data: { users: siteService.siteObject.users  },
        method: 'Post'
    })

This is my mvc web api controller (Try with [FromBody] attribute and without)

   [Authorize(Roles = "admin")]
    [HttpPost]
    public List<graph_item> graph([FromBody] DaganUser[] users)
    {
     ...
    }

In the browser console seems that the data pass to server, But the controller parameter always null

enter image description here

share|improve this question
up vote 2 down vote accepted

You are passing object

Convert this

public List<graph_item> graph([FromBody] DaganUser[] users)

to this

public List<graph_item> graph([FromBody] DaganUser users)

And DaganUser should have the property name users as you are passing object with property users

share|improve this answer

Anik Islam Abhi You give me the direction to the solution, and instead of passing

 data: { users: siteService.siteObject.users  },

I wrote

  $http({
                url: '/api/messages/graph',
                data:  siteService.siteObject.users  ,
                method: 'Post'
            })

And now it work Thanks

share|improve this answer

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.