IList를 Html.CheckBoxFor에 바인딩하려고합니다.IList를 CheckBoxFor에 바인딩하면 체크 된 값이 반환되지 않습니다. MVC
내가 처음 시도하고 조사했을 때 KeyValuePair는 개인적인 특성 때문에 작업을 수행하지 않을 것이므로 MyKeyValuePair를 만들었습니다. 그래서 지금 내 모델에서 내가 가진 :
@Html.CheckBoxFor(model => model.MyProperty.Value)
@foreach (var f in Model.Orientation)
{
@Html.CheckBoxFor(model => f.Value)
}
문제점가 IList의 내부에 그 MyKeyValuePair 자신의 값을 업데이트하지 않습니다,하지만 MyProperty는 :
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)
@for (var i=0; i < Model.Orientation.Count; i++)
{
@Html.CheckBoxFor(model => Model.Orientation[i].Value)
}