這個問題已經快把我逼瘋了,並星期一上午沒有真正幫助那些與價值。DropDownList的了selectedValue沒有得到來自DB
我加載2個dropdownboxes像這樣:
這一個被其受分貝值的SelectedValue
<dd><%= Html.DropDownList("type", New SelectList(ViewData("typeList"), "value", "text", Model.type), New With {.class = ""})%></dd>
這其中忽略了模型,並始終顯示加載的值下拉框中的第一個值
<dd><%= Html.DropDownList("action", New SelectList(ViewData("actionList"), "value", "text", Model.action), New With {.class = ""})%></dd>
我已經調試過這個頁面,Model.Action加載了正確的值,但他們從來沒有被分配到選定的值。
編輯:
這是一個顯示頁面的ActionResult:
<Authorize()> _
Public Function Edit(ByVal id As Guid) As ActionResult
Dim article As Article_Ad = articleAdRepository.GetById(id)
ViewData("actionList") = GetActionValues()
ViewData("typeList") = GetTypeValues()
Return View(article)
End Function
而且這些都是喂dropdownboxes功能:
Private Function GetTypeValues() As IEnumerable(Of SelectListItem)
Dim list As New List(Of SelectListItem)
Dim sel As SelectListItem
'Imagem
sel = New SelectListItem
sel.Text = "Imagem"
sel.Value = "image"
list.Add(sel)
'Video
sel = New SelectListItem
sel.Text = "Video"
sel.Value = "video"
list.Add(sel)
Return list
End Function
Private Function GetActionValues() As IEnumerable(Of SelectListItem)
Dim list As New List(Of SelectListItem)
Dim sel As SelectListItem
' Call browser window
sel = New SelectListItem
sel.Text = "Mostrar Janela"
sel.Value = 1
list.Add(sel)
' Play fullscreen video
sel = New SelectListItem
sel.Text = "Mostrar Video em FullScreen"
sel.Value = 2
list.Add(sel)
' Show fullscreen picture
sel = New SelectListItem
sel.Text = "Mostrar Imagem em FullScreen"
sel.Value = 3
list.Add(sel)
Return list
End Function
我們可以看到生成的SelectList的傳遞給你的視圖的代碼? –
@大衛,我已經添加了你請求我的信息的信息。謝謝。 – Hallaghan
只是澄清了問題 - 您期望兩個下拉列表中的選定值設置正確嗎?我的VB可能有點生疏,但你在哪裏設置選定的值? –