2
在編輯觀點: 我傳遞ViewBag列表中DDLMVC3下拉列表重載和設定值
控制器:
ViewBag.CountryList = new SelectList(db.Country, "CountryCode", "Desc");
在編輯視圖
: 如何將viewbag分配給DDL和設置來自模型的值
@Html.EditorFor(model => model.CountryCode) <- contains the Desc Value, currently just shows in a textbox!
thx!
使用'@ Html.DropDownListFor'。如果你閱讀了C#指定的你需要的參數,它的自我解釋。事實上,你已經在viewbag中擁有了selectList,這意味着你幾乎已經完成了所有工作。 – Doomsknight 2012-04-19 16:45:39