前台:
@using (Html.BeginForm()) { @Html.ValidationSummary(true) <table> <tr> <th> 选择 </th> <th> </th> </tr> @foreach (var item in Model) { <tr> <td> <input type="checkbox" id="checkboxRole" name="checkboxRole" value="@item.Value" /> </td> <td> @item.Name
</td> </tr> } </table> <p> <input type="submit" value="Save" /> </p> }
后台:
if(collection.GetValues("checkboxRole")!=null) { string strRoles = collection.GetValue("checkboxRole").AttemptedValue; string[] lstRoles = strRoles.Split(','); //获取到所选内容 //..........你的代码.......... }