0

I have one ajax call :

  var arr = [1, 2, 3];
  $.ajax({
      url: "http://localhost:14506/api/Lanche/Montar",
      type: "POST",
      data: { id: arr },
      dataType: "json",
      async: false,
      success: function (data) {
          alert(data);
      }
  });

Sending to one WebApi Controller

public decimal Montar( int[] id )
        {
            if (id != null)
            {
                // code here
            }
            return 0;
        }

But always this id comes with 0 items, what´s wrong ?

jleach
  • 7,410
  • 3
  • 33
  • 60
NIZZOLA
  • 39
  • 8
  • Possible duplicate of [Pass array to mvc Action via AJAX](https://stackoverflow.com/questions/5489461/pass-array-to-mvc-action-via-ajax) – Dani Apr 15 '18 at 19:48

1 Answers1

0

Try giving [FromBody] to force Web API to read type from the request body

public decimal Montar([FromBody] int[] id )
 {
    if (id != null)
    {
                // code here
    }
    return 0;
 }
ssilas777
  • 9,672
  • 4
  • 45
  • 68