@Html.DropDownList("days", new List<SelectListItem>
{
new SelectListItem { Text = "MONDAY", Value = "1"},
new SelectListItem { Text = "TUESDAY", Value = "2"},
new SelectListItem { Text = "WEDNESDAY", Value = "3"},
new SelectListItem { Text = "THUSDAY", Value = "4"},
new SelectListItem { Text = "FRIDAY", Value = "5"},
new SelectListItem { Text = "SATURDAY", Value = "6"},
new SelectListItem { Text = "SUNDAY", Value = "7"}
})
SelectListItem讓我們自行設定每一個清單項目所要顯示的文字以及對應的value屬性值,這一段配置會得到以下的結果。
<select id="days" name="days"><option value="1">MONDAY</option>
<option value="2">TUESDAY</option>
<option value="3">WEDNESDAY</option>
<option value="4">THUSDAY</option>
<option value="5">FRIDAY</option>
<option value="6">SATURDAY</option>
<option value="7">SUNDAY</option>
</select>
@Html.DropDownList("days", new SelectList(listItems, "Value", "Text"))
至於清單格式的 ListBox 原理相同,請自行測試。
沒有留言:
張貼留言