我想创建一个能够设置 ID 的下拉列表(因为我有两个来自同一个视图包)。就像是
@Html.DropDownList("startTimes", (SelectList)ViewBag.times, new { @class = "date" })
@Html.DropDownList("endTimes", (SelectList)ViewBag.times, new { @class = "date" })
现在,我有
ViewBag.times = getTimeList();
private List<SelectListItem> getTimeList() { List<SelectListItem> times = new List<SelectListItem>(); for (int Minutes = 60; Minutes < 770; Minutes += 30) { TimeSpan TS = TimeSpan.FromMinutes(Minutes); String TSString = String.Format("{0:00}:{1:00}", TS.Hours, TS.Minutes); SelectListItem item = new SelectListItem(); item.Text = TSString; item.Value = TS.Minutes.ToString(); times.Add(item); } return times; }
但我收到一个错误:无法将类型“System.Collections.Generic.List”转换为“System.Web.Mvc.SelectList”