我有以下课程:
public class ControllerSecurityModel
{
public string ControlleName { get; set; }
public string DisplayName { get; set; }
public List<ActionSecurityModel> actions { get; set; }
}
public class ActionSecurityModel
{
public string ActionName { get; set; }
public string DisplayName { get; set; }
public bool IsChecked { get; set; }
}
和一个模型:
public class PageRoleModel
{
public List<ControllerSecurityModel> AllPages { get; set; }
public List<ControllerSecurityModel> SelectedPage { get; set; }
}
我想为每个“ActionSecurityModel”设置复选框,我写在下面的视图:
<% using (Html.BeginForm())
{%>
<% foreach (var cont in Model.AllPages)
{%>
<fieldset>
<legend>
<%= cont.DisplayName %></legend>
<% foreach (var act in cont.actions)
{%>
<%: Html.CheckBoxFor(x => act.IsChecked) %>
<%: Html.Label(act.DisplayName) %>
<% } %>
</fieldset>
<% } %>
<input type="submit" value="save"/>
<% } %>
这是我的控制器动作:
public ActionResult SetRole()
{
PageRoleModel model = new PageRoleModel();
return View(model);
}
[HttpPost]
public ActionResult SetRole(PageRoleModel model)
{
return View(model);
}
但是当我提交表单时,模型为空?如何提交复选框并保存它们?