5
In my application I am printing a list of data coming database, and in each item of the list I am placing a checkbox, as shown in the following picture:
Now by clicking "Start copy" I want to select the items from the list that are selected, and the respective value
.
Printing the list in the view I’m doing:
<div style="width: 40%; height: 60%; overflow-y: scroll;">
@foreach (var item in ViewBag.estabelecimentos)
{
<input type="checkbox" value="@item.IdFilial" name="filialCopia"/>@item.Nome<br />
}
</div>
<button type="button" class="btn btn-primary" onclick="FazerCopiaEstabs()">Iníciar cópia</button>
To ViewBag.estabelecimentos
is my list of data returned from controller.
Now to fetch the values of the selected checkbox I am doing (javascript):
function FazerCopiaEstabs() {
var fields = $("input[name='filialCopia']").serializeArray();
$.each(fields, function (index, itemData) {
alert(itemData.val());
})
}
In the code above I’m just trying to get the value
from each selected checkbox, then send to the controller and start the data copy. But without success... I can’t get the selected Dropbox