Model view controller MVC 4.0 Razor未绑定到Post上的模型的复选框列表
我试图根据数据库中存储的组的数量填充MVC视图上的复选框列表 复选框项的模型:Model view controller MVC 4.0 Razor未绑定到Post上的模型的复选框列表,model-view-controller,mvvm,Model View Controller,Mvvm,我试图根据数据库中存储的组的数量填充MVC视图上的复选框列表 复选框项的模型: public class CheckListItem { public int Value { get; set; } public string Text { get; set; } public bool Selected { get; set; } } 页面的ViewModel包含上述内容的列表 public List<
public class CheckListItem
{
public int Value { get; set; }
public string Text { get; set; }
public bool Selected { get; set; }
}
页面的ViewModel包含上述内容的列表
public List<CheckListItem> MeGroupList { get; set; }
public List MeGroupList{get;set;}
他认为:
@for (var i = 0; i < MeGroupList.Groups.Count(); i++)
{
@Html.HiddenFor(x => x.MeGroupList[i].Value)
@Html.HiddenFor(x => x.MeGroupList[i].Text)
@Html.CheckBoxFor(x => x.MeGroupList[i].Selected, new { @class = "form-check-input" })
<label class="form-check-label" style="margin-right: 10px">
<font color="black"><b> @Model.MeGroupList[i].Text</b></font>
</label>
}
for(var i=0;i<input data-val="true" data-val-number="The field Value must be a number." data-val-required="The Value field is required." id="MeGroupList_0__Value" name="MeGroupList[0].Value" type="hidden" value="1">
<input id="MeGroupList_0__Text" name="MeGroupList[0].Text" type="hidden" value="BIW">
<input class="form-check-input" data-val="true" data-val-required="The Selected field is required." id="MeGroupList_0__Selected" name="MeGroupList[0].Selected" type="checkbox" value="true">
<input name="MeGroupList[0].Selected" type="hidden" value="false">
<label class="form-check-label" style="margin-right: 10px">
<font color="black"><b> BIW</b></font>
</label>
白车身
当我提交表单并检查模型时,MeGroupList计数为零。没有任何东西是绑定回邮政的。我花了一天时间尝试了很多不同的方法,但都没有成功。我不能把它绑在柱子上。我在网上的各种文章中找到了上述内容,就我所知,这些内容与所示的示例完全相同。任何帮助都将不胜感激