This is my HTML:
<ul id="limitations" name="limitations" class="dropdown-menu">
<li>
<div class="checkbox checkbox-default">
<input type="checkbox" id="limitation-checkbox-0" value="8" name="limitations[0]" data-name="ALS ">
<label for="limitation-checkbox-0" style="color:black">ALS </label>
</div>
</li>
<li>
<div class="checkbox checkbox-primary">
<input type="checkbox" id="limitation-checkbox-1" value="10" name="limitations[1]" data-name="Arthrogryposis Multiplex Congenita (AMC) & Amyoplasia">
<label for="limitation-checkbox-1" style="color:black">Arthrogryposis Multiplex Congenita (AMC) & Amyoplasia</label>
</div>
</li>
<li>
<div class="checkbox checkbox-success">
<input type="checkbox" id="limitation-checkbox-2" value="2" name="limitations[2]" data-name="Cerebral Palsy (CP), (GMFS)">
<label for="limitation-checkbox-2" style="color:black">Cerebral Palsy (CP), (GMFS)</label>
</div>
</li>
<li>
<div class="checkbox checkbox-info">
<input type="checkbox" id="limitation-checkbox-3" value="4" name="limitations[3]" data-name="Hearing impairment deafness or hard of hearing">
<label for="limitation-checkbox-3" style="color:black">Hearing impairment deafness or hard of hearing</label>
</div>
</li>
... MORE <li> ...
</ul>
When I post the form, the model binder for List<int> limitations works only if the checkboxes are selected from, if there is a gap in the array, all items after the gap are not binded.
For example:
Consider the first(8) and the third(10) checkboxes are checked.
The value binded to List<int> limitations is [8].
Or if all the checkboxes are checked, List<int> limitations is binded witn an empty list.
I tried changing names of the checkboxes from name="limitations[0..n]" to name="limitations[]" but that caused ASP.NET to completely ignore the values.
Isn't there a standard for such things?!
I know how I can overcome this with javascript manipulation, but I really rather not going that awkward route for such a trivial case.
Using asp.net core 1.0.0 and .Net4.6.1
namefor all checkboxes toname="limitations". The model binder forint[] limitationsorList<int> limitationswill work.