0

Could I get some help with this issue please:

I'm trying to send an array of int from my javascript function to my api controller but can't get the correct configuration for the controller - the projectsId passed into the controller is always null.

Javascript function:

    getProducts: function (projects) {            
        return $http({
            method: 'POST',
            url: '/api/settings/products',
            data: projects
        }).then(function (result) {
            return result.data;
        }, function (result) {
            return result;
        });

The projects being passed ito getProducts is an int array.

Controller:

    [HttpPost]
    [Route("products")]
    public IHttpActionResult Export([FromBody] int[] projectIds)
    {
        var exportProducts = new List<Product>();

Thank you.

This is the result of console.log(projects): This is the result of console.log(projectIds)

0

1 Answer 1

1

where you'e calling getProducts the input parameter should look something like:

var products = [1, 2, 3];

To assist with debugging, add a console.log(projects) to your getProducts function.

2
  • Thanks for your reply David - I've added the console.log(projects) .. Commented Jul 9, 2020 at 8:47
  • Thanks David! The problem is with the array I was passing in. It is not equalivent to var products = [1,2,3]. When populated this as a test it worked. Man alive! thanks very much! Commented Jul 9, 2020 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.