A small question where I think I'm very close to the goal.
I am trying to retrieve the value of all checkboxes coming from an array that are checked in order to send these values to my controller. (This allows the user to select or not certain options).
I'm almost there, I just can not get the desired value in my int table.
I would like to put int in this int array the value '@ stuff.SubEvent_Zkp' but currently .val () puts 0 as a value in all the checkboxes sent to my controller (and also in the ajax call).
I still specify that # stuff.SubEvent_Zkp has a unique value.
I tried with data [0] and also with attr () but that does not seem to work.
Table with checkboxes
<tbody>
@foreach (var stuff in Model._Registration_SubEvents)
{
<tr>
<td class="col-md-3">@stuff.SubEvent_Name</td>
<td class="col-md-1">@stuff.SubEvent_Date.ToShortDateString()</td>
<td>@stuff.SubEvent_Fee</td>
<td>@stuff.SubEvent_Note</td>
<td><input style=" height:17px; width:17px; margin-top:5px; margin-left:22px" type="checkbox" name="CheckSub" id="CheckSub" value="@stuff.SubEvent_Zkp" /></td>
</tr>
}
</tbody>
Code to put the values of @stuff.SubEvent_Zkp in favorite array
$.each($("input[name='CheckSub']:checked"), function () {
favorite.push($(this).val());
});
And i put favorite in data (in the ajax call)
data: { Id: id, Status: status,Checkin: checkin, Checkout: checkout, Cost: cost, Terms: check1, Info: check2, values: favorite },
eachlooks fine