Razor DropDownListFor没有传递模型

时间:2014-09-18 15:10:32

标签: razor dropdownbox dropdownlistfor

如何显示此列表

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需要一个模型作为第一个参数,但我不需要下拉列表模型才能达到我的目的。

由于

1 个答案:

答案 0 :(得分:3)

您可以使用

@Html.DropDownList("name", dates)

name是您的下拉列表的名称(在下拉菜单的idname中使用)。

@Html.DropDownListFor()确实适用于有模特的情况。