1

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

2 Answers 2

2

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

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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.