Reputation: 1975
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
Upvotes: 1
Views: 4308
Reputation: 1975
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
Upvotes: 0
Reputation: 25352
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
Upvotes: 2