如何让它每 5 计数一次(5,10,15,20 等)
@Html.DropDownListFor(model => model.StartMinute, Enumerable.Range(1, 60).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString() }), "Minute", htmlAttributes: new { @class = "form-control" })
与其生成所有数字并跳过您不需要的数字,不如只生成所需的数字:
Enumerable.Range(0,12).Select(n => 5*n)
这将生成 0, 5, 10, .., 55
或者用.Range(1,12)
从 5 数到 60。
只需要添加 where 条件,该条件将仅选择那些可被 5 整除的数字。
@Html.DropDownListFor(model => model.StartMinute, Enumerable.Range(1, 60).Where(x => x%5 == 0).Select(i => new SelectListItem { Value = i.ToString(), Text = i.ToString() }), "Minute", htmlAttributes: new { @class = "form-control" })