2012-09-04 36 views
2
@Html.DropDownListFor(model => model.title, (SelectList)ViewBag.NoVList, new { id = "natureOfVisit", @class = "text white" }) 

如何向此DropDownListFor添加deafult值。我的意思是當用戶打開彈出窗口來編輯模型,在這個下拉列表中,從下拉框中選擇當前的model.title值。Deafult value loading爲HTML.DropDownListFor

回答

0

要爲下拉列表設置默認值,你應該建立相應的SelectList:

ViewBag.NoVList = new SelectList(novs, "valueField", "textField", 1); 

novs [1]這裏將是默認選擇。

+0

歡迎您:) – karaxuna

2

試試這個:

@Html.DropDownListFor(model => model.title, (SelectList)ViewBag.NoVList, "Please Select...", new { id = "natureOfVisit", @class = "text white" }) 

第三個參數是optionLabel