我正在尝试将 IList 绑定到 Html.CheckBoxFor。
当我第一次尝试和调查时,我发现 KeyValuePair 因为它的私有性质而无法完成这项工作,所以我做了一个 MyKeyValuePair。所以现在在我的模型中我有:
public GameCreation()
{
Orientation = new List<MyKeyValuePair>();
foreach (var v in Enum.GetNames(typeof(DeveloperPortalMVCApp.Models.Orientation)))
{
Orientation.Add(new MyKeyValuePair { Name = v });
}
}
public MyKeyValuePair MyProperty { get; set; }
public ObservableCollection<MyKeyValuePair> Orientation { get; set; }
我的看法是:
@Html.CheckBoxFor(model => model.MyProperty.Value)
@foreach (var f in Model.Orientation)
{
@Html.CheckBoxFor(model => f.Value)
}
问题是 IList 中的那些 MyKeyValuePair 不会更新它们的值,但 MyProperty 会。我错过了什么?