I have a jQuery ajax call in which I am trying to send the int IDs of users which can be selected from a table of checkboxes.
I am having a problem with the case that no users are selected. I would expect an empty array but in fact I receive an array of length = 1, containing userId 0 (i.e. an unassigned int value).
The following snippet reproduces the problem
$('#test').click(function () {
var numbers = $('.noElements').map(function () {
// (selector does not match any elements, to demonstrate)
return 1;
}).get();
$.ajax({
url: '/MyController/Test',
type: "GET",
data: { numbers: numbers, count: numbers.length }
});
});
public ActionResult Test(IEnumerable<int> numbers, int count)
{
Assert(numbers.Count() == count);
return null;
}
The Assert fails because numbers
is List<int> { 0 }
. Why is the binding happening like this?