ViewData["myList"] =
new SelectList(new[] { "10", "15", "25", "50", "100", "1000" }
.Select(x => new {value = x, text = x}),
"value", "text", "15");
次に、あなたの見解で:
@Html.DropDownList("myList")
または、linq を使用して選択リストを生成できます
IList<Customer> customers = repository.GetAll<Customer>();
IEnumerable<SelectListItem> selectList =
from c in customers
select new SelectListItem
{
Selected = (c.CustomerID == invoice.CustomerID),
Text = c.Name,
Value = c.CustomerID.ToString()
};
あなたの場合:
List<SelectListItem> ls = new List<SelectListItem>();
ls.Add(new SelectListItem() { Text = "Yes", Value = "true", Selected = true });
ls.Add(new SelectListItem() { Text = "No", Value = "false", Selected = false });
ls.Add(new SelectListItem() { Text = "Not Applicable", Value = "NULL", Selected = false });
ViewData["myList"] = ls;