选中checkbox
页面:
@foreach (string item in ViewBag.ListItem)
{
<input type="checkbox" value="@item" name="@item" @(ViewBag.CheckListItem.Contains(@item)==true?"checked=‘checked‘":"") />@item
}
Controller:
List<string> ListItem = new List<string> { "zhangsan", "lisi", "wangwu", "maliu", "li" };
List<string> checkListItem = new List<string> { "lisi", "wangwu" };
ViewBag.ListItem = ListItem;
ViewBag.checkListItem = checkListItem;
时间: 2025-01-07 19:11:34