Asp.net mvc 4 ViewBag选择列表日期时间到日期

Asp.net mvc 4 ViewBag选择列表日期时间到日期,asp.net-mvc-4,selectlist,viewbag,Asp.net Mvc 4,Selectlist,Viewbag,在我的控制器中- ViewBag.DatesEnum = new SelectList(_db.blah.Where(w => w.Active == true).AsEnumerable(), "ID", "Date"); 鉴于- @Html.DropDownListFor(m => m.blahDate, (SelectList)ViewBag.DatesEnum) Ofc它是一个传入的日期时间值,我想知道如何最好地将它转换为ToSortDateString ViewBag.

在我的控制器中-

ViewBag.DatesEnum = new SelectList(_db.blah.Where(w => w.Active == true).AsEnumerable(), "ID", "Date");
鉴于-

@Html.DropDownListFor(m => m.blahDate, (SelectList)ViewBag.DatesEnum)
Ofc它是一个传入的日期时间值,我想知道如何最好地将它转换为ToSortDateString

ViewBag.DatesEnum = _db.blah.Where(w => w.Active == true)
                            .AsEnumerable()
                            .Select(i => new SelectListItem
                                        {
                                            Value = i.ID,
                                            Text = i.Date.ToShortDateString()
                                        });
然后可以在视图中显示下拉列表

@Html.DropDownListFor(m => m.blahDate, 
                           (IEnumerable<SelectListItem>)ViewBag.DatesEnum)
@Html.DropDownListFor(m=>m.blahDate,
(IEnumerable)ViewBag.DatesEnum)
如果向模型中添加下拉数据并跳过使用ViewBag,效果会更好