I have the following code. Why can't I have an array or list as inparameter directly? It works fine with an array or list inside a class like below.
Request payload:
{"ids":[1,2,4]}
Angular:
send: {
method: 'POST',
url: controllerPath + '/send',
isArray: true
}
agreementResource.send({ ids: vm.agreementIds }).$promise.then(function (data) {
});
C#:
//Works
[HttpPost]
[Route("send")]
[Authorize(Roles = "Admin")]
public IHttpActionResult Send(AgreementIdsViewModel ids)
{
foreach (var id in ids.Ids)
{
}
}
//Does not work
[HttpPost]
[Route("send")]
[Authorize(Roles = "Admin")]
public IHttpActionResult Send(int[] ids)
{
foreach (var id in ids)
{
}
}
public class AgreementIdsViewModel
{
public int[] Ids { get; set; }
}
I know it can be done via GET-request so I think it should be possible.
GetSend([FromUri] int[] ids)
And send request:
/Send?ids=1&ids=2&ids=3
public IHttpActionResult Send([FromBody] int[] ids)