我有我的觀點一個DDL,我從DB這樣的閱讀DDL的項目和值:在DDL(MVC4)設置的第一項的值設置爲null
ViewBag.ContentGroup = new SelectList(obj.GetContentGrouplist(), "Id", "Name");
我把它放在viewbag和我讀到這樣從視圖中viewbag:
<div class="editor-label">
@Html.LabelFor(model => model.ContentGroupFKId)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.ContentGroupFKId, (SelectList)ViewBag.ContentGroup)
@Html.ValidationMessageFor(model => model.ContentGroupFKId)
</div>
所以我需要的是,第一項爲空我怎麼做一個DDL?
我試過,但它不工作:
@Html.DropDownListFor(x => x.ContentGroupFKId,new SelectList(new List<Object> {new {value = null, text = "Select"} (SelectList)ViewBag.ContentGroup)
最好的問候。
所以,我該怎麼辦呢?我的意思是「‘請選擇一個項目’ –
增加了一些細節 – bsayegh
謝謝@ bsayegh –