public IEnumerable GetList(int? ID)
{
return from s in db.List
orderby s.Descript
select new SelectListItem
This is just for people who are using Webpages framwork (not MVC and webform) with Razor V2 and C#, you need do
@Html.DropDownList("category", "Please select", listData)
Note: OptionalLabel need to be the middle parameter.
Equivalent would be add a SelectListitem to your list data:
var list=db.Query("select id, name from dbtable");
List<SelectListItem> listData = new List<SelectListItem>();
listData.Add(new SelectListItem
{
Text = "Please select",
Value = "",
});
foreach(var item in list) {
listData.Add(new SelectListItem {
Text = item.Name,
Value = item.id,
Selected = isSelected
});
}
@Html.DropDownList("play" , listData)