5
我有一個模型,該模型具有public List<string> Hour { get; set; }
和構造模型綁定下拉列表中選擇值
public SendToList()
{
Hour = new List<string> { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" };
}
我的問題是,爲什麼我沒有拿到一個選定值這個
@Html.DropDownListFor(model => model.Hour, Model.Hour.Select(
x => new SelectListItem
{
Text = x,
Value = x,
Selected = DateTime.Now.Hour == Convert.ToInt32(x)
}
))
但我在這裏得到了一個選定的值。
@Html.DropDownList("Model.Hour", Model.Hour.Select(
x => new SelectListItem
{
Text = x,
Value = x,
Selected = DateTime.Now.Hour == Convert.ToInt32(x)
}
))
有什麼區別?
感謝你爲這個。使發送具有選定值的道具。愛範圍聲明,不知道它。我還可以在會議記錄中使用它嗎?我只想給出0,5,10的選項.... – 2011-02-28 13:18:21
我知道它有點晚了,但要在您的評論中回答您的問題,您可以在where語句中進行模數化,例如.Where(x => x% 5 <= 0) – Sam 2011-08-11 12:35:17