1
我試圖將ASP.NET MVC中的下拉列表綁定到類。幸運的是,這將是一個介於1到10之間的數字,但是我沒有得到我期望的HTML輸出。我已經在視圖中設置了填充好的值和文本屬性,但所選值拒絕呈現。這是我的控制器的初始編輯方法。有任何想法嗎?將簡單的排序下拉列表綁定到MVC中的列表
Dim SC As SuperCategory = Model.Fast.Pull(DB.SuperCategory, ID)
Dim list As New List(Of SelectListItem)
list.Add(New SelectListItem With {.Value = 1, .Text = "1", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 2, .Text = "2", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 3, .Text = "3", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 4, .Text = "4", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 5, .Text = "5", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 6, .Text = "6", .Selected = True})
list.Add(New SelectListItem With {.Value = 7, .Text = "7", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 8, .Text = "8", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 9, .Text = "9", .Selected = (.Value = SC.Sort)})
list.Add(New SelectListItem With {.Value = 10, .Text = "10", .Selected = (.Value = SC.Sort)})
ViewData("Sort") = list
HTML視圖中看起來像這樣:
排序: <%= Html.DropDownList( 「排序」,CTYPE(ViewData的( 「排序」),IEnumerable的(中SelectListItem)))% >