7
我需要显示复选框列表,可以选中多个复选框。MVC3如何将多个复选框绑定到ViewModel中的1个属性
当用户点击提交,这些复选框的值需要进入的视图模型的属性......这是我走到这一步......
public class RegisterModel
{
public List<string> Roles { get; set; }
public List<RoleModel> SelectedRoles { get; set; }
}
public class RoleModel
{
public string RoleName { get; set; }
}
在视图我想要做到这一点...
@foreach (var role in Model.Roles)
{
@Html.CheckBoxFor(m => m.SelectedRoles, role.RoleName)@role.RoleName
}
我得到以下错误:
CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<string>' to 'bool'
谁能告诉我什么,我做错了什么?
感谢您的快速响应! – thiag0
@ thiag0,不客气。 –
这么简单,它的效果很棒! – tsquillario