我想知道是否可以将Dictionary的值绑定到CheckBoxFor吗?
我试图这样做:
@for (int c = 0; c < Model.ObjectsWithPermission[a].PermissionColumns.Count; c++)
{
<tr>
<td>
@Model.ObjectsWithPermission[a].PermissionColumns[c].Name
</td>
@for (int i = 0; i < Model.ObjectsWithPermission[a].PermissionColumns[c].Permissions.Count; i++)
{
<td align="center">
@*@Html.CheckBox(permission.Key, permission.Value)*@
@Html.CheckBoxFor(x => Model.ObjectsWithPermission[a].PermissionColumns[c].Permissions.ElementAt(i).Value)
</td>
}
[Display(Name = "Groups")]
public PermissionMatrix GroupsWithPermission { get; set; }
PermissionMatrix
public string Name { get; set; }
public List<PermissionMatrixColumn> PermissionColumns { get; set; }
PermissionMatrixColumn
private void Init()
{
//I want to bind it to these values
Permissions = new Dictionary<string, bool>()
{
{"SELECT",false},
{"INSERT",false},
{"UPDATE",false},
{"ALTER",false},
{"DELETE",false},
};
}
public PermissionMatrixColumn(string name)
{
Init();
Name = name;
}
public PermissionMatrixColumn()
{
Init();
}
public string Name { get; set; }
[Display(Name = "Permissions")]
public Dictionary<string, bool> Permissions { get; set; }
如果我设置了一个复选框并提交,则给控制器的给定模型未选中此值(true)。
public ViewResult Index(TableModel model)
{