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

神不在的星期二
TA貢獻(xiàn)1963條經(jīng)驗 獲得超6個贊
使用接受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)注
- 618 瀏覽
添加回答
舉報
0/150
提交
取消