I've got a table with row data. Each row has a checkbox that will flag that row for processing. The table is populated with the aid of a DisplayTemplate as can be seen in the below code. When the user clicks the "Process" button, the code should iterate the table and add all selected rows to an array that will be sent to a web service. I thought this would be a simple thing to find an example on, but this hasn't been the case.
This is the table:
<table id="hes" class="table-striped table-condensed table-bordered">
<thead>
<tr>
<th></th>
<th>Detail Id</th>
<th>Detail Reason Code</th>
<th>Detail Status Code</th>
</tr>
</thead>
<tbody>
@if (Model.HesViewModels != null)
{
@Html.DisplayFor(i => i.HesViewModels)
}
</tbody>
I'm using this JQuery code to get the selected row and can't figure out how to get the row and it's corresponding values into an array.
$('#process').click(function () {
var x = $('#hes tr').find('input[type="checkbox"]:checked').each(function () {
// GET THE VALUES OF THE TDs ON THIS ROW AND STICK IN AN ARRAY
});
});
EDIT - Here's what the rendered source looks like for each row:
<tr>
<td><input data-val="true" data-val-required="The Process field is required." id="HesViewModels_0__Process" name="HesViewModels[0].Process" type="checkbox" value="true" /><input name="HesViewModels[0].Process" type="hidden" value="false" /></td>
<td>500116</td>
<td>0</td>
<td>1</td>
</tr>