我在控制器中創(chuàng)建一個(gè)selectList,以顯示在視圖中。我正在嘗試即時(shí)創(chuàng)建它,就像這樣...myViewData.PageOptionsDropDown = new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15");它可以編譯,但是輸出是錯(cuò)誤的...<select id="PageOptionsDropDown" name="PageOptionsDropDown"> <option>10</option> <option>15</option> <option>25</option> <option>50</option> <option>100</option> <option>1000</option></select>請(qǐng)注意如何沒有選擇任何項(xiàng)目?我怎樣才能解決這個(gè)問題??
3 回答

神不在的星期二
TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊
使用接受items, dataValueField, dataTextField, selectedValue作為參數(shù)的構(gòu)造函數(shù):
ViewData["myList"] =
new SelectList(new[] { "10", "15", "25", "50", "100", "1000" }
.Select(x => new {value = x, text = x}),
"value", "text", "15");
然后在您看來:
<%=Html.DropDownList("myList") %>
- 3 回答
- 0 關(guān)注
- 612 瀏覽
添加回答
舉報(bào)
0/150
提交
取消