【问题标题】:Razor DropDownListFor without passing modelRazor DropDownListFor 不通过模型
【发布时间】:2014-11-13 00:20:48
【问题描述】:

如何显示此列表

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()},
};

    @Html.DropDownListFor()

?

据我所知,DropDownListFor 需要一个模型作为第一个参数,但我不需要一个模型来使下拉菜单用于我的目的。

谢谢

【问题讨论】:

    标签: razor dropdownbox dropdownlistfor


    【解决方案1】:

    你可以使用

    @Html.DropDownList("name", dates)
    

    name 是下拉列表的名称(用于下拉列表的 idname)。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多