I've been searching for an article or example but can't seem to find what I'm looking for. If I write out a table in a View with a checkbox in one of the columns, how would I go about looping through the row, seeing if the checkbox is checked, and if it is then add the record to a database?
I'm still learning about checkboxes and dropdownlists in MVC so I will eventually have to figure out how I would assign the UserID to the row or checkbox and then I'll look at a dropdownlist for the GroupId to assign them to.
The basic scenario is to have a list of unassigned users with a dropdownlist of Groups above the table. The Admin will then make a selection of which group from the DDL and then check the users he wants to assign to it. Then I need to loop through get the UserId for the records that were checked and add them to a database with EntityFramework.
Anyone know of any examples or articles for something similar?
<table class="table table-bordered table-striped table-hover table-condensed tbackground">
<tr>
<th class="text-center">
</th>
<th class="text-center">
First Name
</th>
<th class="text-center">
Last Name
</th>
<th class="text-center">
Email
</th>
<th class="text-center">
Phone
</th>
</tr>
@foreach (var item in Model)
{
if (item.GroupId == 0)
{
<tr>
<td>
@Html.CheckBox("isSelected")
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
<a href="mailto:@item.EmailPrimary">@item.EmailPrimary</a>
</td>
<td class="text-center">
@Html.DisplayFor(modelItem => item.PhonePrimary)
</td>
</tr>
}
}
</table>