如何显示此列表
var dates = new List<SelectListItem>
{
new SelectListItem {Selected = false, Text = "Show offers for all dates", Value = ""},
new SelectListItem {Selected = false, Text = "Show offers for today", Value = today.ToShortDateString()},
new SelectListItem {Selected = false, Text = "Show offers for this week", Value = endOfThisWeek.ToShortDateString()},
new SelectListItem {Selected = false, Text = "Show offers for this month", Value = endOfThisMonth.ToShortDateString()},
new SelectListItem {Selected = false, Text = "Show offers for further out", Value = all.ToShortDateString()},
};
in
@Html.DropDownListFor()
据我所知,DropDownListFor需要一个模型作为第一个参数,但我不需要下拉列表模型才能达到我的目的。
由于
答案 0 :(得分:3)
您可以使用
@Html.DropDownList("name", dates)
name
是您的下拉列表的名称(在下拉菜单的id
和name
中使用)。
@Html.DropDownListFor()
确实适用于有模特的情况。