Say I have a view like this:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#assign">
Assign
</button>
<table class="table table-hover table-bordered table-sm">
<thead class="thead-light">
<tr>
<th></th>
<th>Name</th>
</tr>
</thead>
@foreach (var employee in ViewBag.employees)
{
<tr>
<td><input type="checkbox" name="@employee.Id" /></td>
<td>@employee.Name</td>
</tr>
}
</table>
<!-- Modal -->
<div class="modal fade" id="assign" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalTitle">Assign employee to group</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- a dropdown of groups -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary">Assign</button>
</div>
</div>
</div>
</div>
And I have a controller to call:
public ActionResult Assign(List<int> employeeIds, int groupId)
How can I get the list of Id
s that are checked and the groupId
from the dropdown in modal, so that I can call the controller?
For example if the data look like this
0. Alice
1. Bob
2. Charlie
3. Dan
And I checked Bob and Charlie and want to assign them to group 1, so the employeeId
s will be 1 and 2, and groupId
will be 1.