I could not bind the model to Controller. Please give me any advice. Model,controller and view classes are below. When model is submmited, dictionary property equals to null.
public class GroupRights //model
{
public List<DtoGrup> groups { get; set; }
public Dictionary<short, Dictionary<EnFunction, bool>> groupRights { get; set; } // group function HasPermission
}
public enum EnFunction
{
LPDU_login,
LPDU_changePassword,
LPDU_transitList,
LPDU_PosEventList,
....
}
Controller
public ActionResult GroupRights()
{
TocCommonService.CommonServiceClient client = new TocCommonService.CommonServiceClient();
GroupRights gr = new GroupRights();
gr.groups = client.GetAllOperatorGroups().ToList();
gr.groupRights = new Dictionary<short, Dictionary<EnFunction, bool>>();
foreach (var g in gr.groups)
{
Dictionary<EnFunction, bool> permission = new Dictionary<EnFunction, bool>();
foreach (var func in Enum.GetValues(typeof(EnFunction)).Cast<EnFunction>())
{
permission.Add(func, client.hasPermission(new DtoGrup() { GROUPID = g.GROUPID }, func));
}
gr.groupRights.Add(g.GROUPID, permission);
}
return View(gr);
}
View
@model TocWebApplication.Models.GroupRights
@{
int id = 0;
}
@using (Html.BeginForm("ChangePermissionOfGroup", "Home", FormMethod.Post))
{
<table>
<thead>
<tr>
<th></th>
@foreach (var gr in Model.groups)
{
<th>@gr.GROUPNAME (@gr.GROUPID)</th>
}
</tr>
</thead>
<tbody>
@foreach (var func in Enum.GetValues(typeof(EnFunction)).Cast<EnFunction>())
{
<tr>
<td>@(func.ToString())</td>
@for (int j = 0; j < Model.groups.Count(); j++)
{
<td>@Html.CheckBoxFor(model => model.groupRights[Model.groups[j].GROUPID][func])</td>
}
</tr>
}
</tbody>
</table>
<button type="submit" class="btn btn-primary">Save changes</button>
<button class="btn">Cancel</button>
}