我有一個名爲[SchoolingLevels]類,使用此代碼:填充單選
public List<SelectListItem> schoolingLevels = new List<SelectListItem>();
public List<SelectListItem> Populate()
{
schoolingLevels.Add(new SelectListItem { Text = "Primary incomplete", Value = "Primary incomplete" });
schoolingLevels.Add(new SelectListItem { Text = "Primary", Value = "Primary" });
schoolingLevels.Add(new SelectListItem { Text = "Secondary incomplete", Value = "Secondary incomplete" });
schoolingLevels.Add(new SelectListItem { Text = "Secondary", Value = "Secondary" });
schoolingLevels.Add(new SelectListItem { Text = "Higher education incomplete", Value = "Higher education incomplete" });
schoolingLevels.Add(new SelectListItem { Text = "Higher education", Value = "Higher education" });
schoolingLevels.Add(new SelectListItem { Text = "Post-graduation/MBA", Value = "Post-graduation/MBA" });
return schoolingLevels;
}
而且我要在此基礎上列表來填充我的單選按鈕..
在我的控制器:
ViewBag.Scholarity = new SchoolingLevels().Populate();
筆者認爲:
@Html.RadioButton("Scholarity", "a")
它不工作..(我用DropDown進行測試並完美工作),RadioButton不可能嗎?
編輯
我試了一下:
@foreach (var myValue in ViewBag.Scholarity)
{
Html.RadioButton("Scholarity","Value")
}
這似乎工作,但我在哪裏可以把單選按鈕的名字嗎?
Ty。
它不起作用?是否有任何事情發生或者它不正確地填充? – SuperBiasedMan
我不這麼認爲,因爲它的下拉工作。 – developer033