0

这是我当前用于简单选择的剃刀代码。

@Html.DropDownList("Season", Model.Seasons.Select(s => new SelectListItem { Text = s.Name, Value = s.SeasonId.ToString() }), new { @class = "sel_season" })

我想要做的是添加/插入一个名为“全部”的附加选项。我已经尝试过 Concat,但我似乎无法让它工作。

@Html.DropDownList("Season", Model.Seasons.Select(s => new SelectListItem { Text = s.Name, Value = s.SeasonId.ToString() }).Concat( new {"All", "0"}), new { @class = "sel_season" })
4

2 回答 2

2

以下示例使用HtmlHelper 类中的重载扩展方法:

@Html.DropDownList("Season"
    , Model.Seasons.Select(s => new SelectListItem {
        Text = s.Name,
        Value = s.SeasonId.ToString()
    })
    , "All"
    , new { @class = "sel_season" }
)
于 2013-03-11T06:05:50.083 回答
0

尝试这个

@Html.DropDownList("Season", 
                  Model.Seasons
                    .Select(s =>
                       new SelectListItem { Text = s.Name, Value = s.SeasonId.ToString() })
                    .ToList().Insert(0, SelectListItem { Text = "All",Value =  "0"}), 
                   new { @class = "sel_season" })
于 2013-03-11T06:04:42.350 回答