I have a problem with a generated droplist, it shows up like this:
<select id="selIntervalStartTime" name="selIntervalStartTime"><option>System.Web.Mvc.SelectListItem</option><option>System.Web.Mvc.SelectListItem</option><option>System.Web.Mvc.SelectListItem</option>&l开发者_StackOverflow中文版t;option>System.Web.Mvc.SelectListItem</option></select>
In my code I have:
List<SelectListItem> si = new List<SelectListItem>();
for (int i = 0; i < 23; i++)
{
si.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
}
return View("ScheduleEdit",
new ScheduleEditViewModel
{
selIntervalStartTime = new SelectList(si)
});
How do I fix this so i.ToString() shows up as value and text?
/M
List<int> si = new List<int>();
for (int i = 0; i < 23; i++)
{
si.Add(i);
}
return View("ScheduleEdit",
new ScheduleEditViewModel
{
selIntervalStartTime = new SelectList(si)
});
or
List<SelectListItem> si = new List<SelectListItem>();
for (int i = 0; i < 23; i++)
{
si.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
}
return View("ScheduleEdit",
new ScheduleEditViewModel
{
selIntervalStartTime = new SelectList(si,"Text","Value")
});
All is good just need 2 more parameters:
selIntervalStartTime = new SelectList(si,"Text", "Value");
精彩评论