我有一个模型,ApplicantBranchList
,在更大的模型中用作属性,如下所示:
[Display(Name = "Where would you want to work?")]
public ApplicantBranchList PreferedBranches { get; set; }
ApplicantBranchList
:
问题是 ASP.NET 无法弄清楚如何绑定到Model.Items
财产。
要修复它,请替换:
public IEnumerable<ApplicantBranchItem> Items { get; set; }
有了这个:
public List<ApplicantBranchItem> Items { get; set; }
而不是:
@foreach (var item in Model.Items)
{
@Html.EditorFor(m => item)
}
使用这个:
@for (var i = 0; i < Model.Items.Count; i++)
{
@Html.EditorFor(model => model.Items[i]) // binding works only with items which are accessed by indexer
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)