开发者

Value + Text for generated SelectList?

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜