承認將selectedItem我想送SelectedList通過ViewBag和控制器,查看我已選定的項目,這是控制器的DropDownList在MVC3不選擇列表的
ViewData["aaa"]= new SelectList(new []{new SelectListItem { Text = "1", Value = "1" },
new SelectListItem { Text = "2", Value = "2"},
new SelectListItem { Text = "25", Value = "25" },
new SelectListItem { Text = "50", Value = "50" },
new SelectListItem { Text = "100", Value = "100" },
new SelectListItem { Text = "1000", Value = "1000" }}, "Text", "Value", "100");
視圖部分
@Html.DropDownListFor(m1 => m1.Sobe,(IEnumerable<SelectListItem>)ViewData["aaa"])
和我得到這個HTML
<select data-val="true" data-val-number="The field Sobe must be a number." data-val-required="The Sobe field is required." id="Sobe" name="Sobe"><option value="1">1</option>
<option value="2">2</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="1000">1000</option>
</select>
,這意味着沒有任何選擇。我不明白,請幫忙
而且我知道如果我DropDownListFor更改爲下拉列表和設置從屬性不同的名稱,將工作,但我不能回來值 – VirtuoZ 2012-03-19 08:51:57