21
에서 가능한 중복 : 당신이 MVC3에서 checkboxlist를 작성하고 제출에 점검 결과를 반환하려면 어떻게
CheckboxList in MVC3 View and get the checked items passed to the controller.CheckboxList MVC3
.
Asp.net MVC3는
에서 가능한 중복 : 당신이 MVC3에서 checkboxlist를 작성하고 제출에 점검 결과를 반환하려면 어떻게
CheckboxList in MVC3 View and get the checked items passed to the controller.CheckboxList MVC3
.
Asp.net MVC3는
당신을 위해이 작업을 수행 할 수있는 프레임 워크에 내장에는 도우미 없습니다. 그러나 그렇게 어렵지 않습니다. ViewBag에 이미 선택 목록이 있다고 가정하면 정상적으로 작동합니다.
@foreach (var o in ViewBag.Options) {
<label><input type="checkbox"
name="MyOptions"
value="@o.Value"/>
<span>@o.Text</span></label>
<br/>
}
당신은 ... 모델은 다음과 같이 배열을 받아 들일 수 있어야합니다
MyOptions
에있을 것입니다 선택
public class MyViewModel {
public ICollection<string> MyOptions { get; set; }
}
값을 볼 수 있습니다.