Pergunta

Estou tentando ligar um dropdownlist em ASP.NET MVC a uma classe. Felizmente para mim, este será um número entre 1 e 10, no entanto Eu não estou recebendo a saída no meu HTML que eu poderia esperar. Eu configurei as propriedades de valor e de texto que são ok populosa do Vista, mas o valor selecionado se recusa a render. Este é dentro do método Editar inicial de meu controlador. Alguma idéia?

    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 nas view parece com isso:

Ordenar: <% = Html.DropDownList ( "Sort", CType (ViewData ( "Ordenar"), IEnumerable (Of SelectListItem)))%>

Foi útil?

Solução

Se implementos ViewData["Sort"] IEnumerable<SelectListItem> não há necessidade no segundo parâmetro. Será que você tente o seguinte:?

<%= Html.DropDownList("Sort") %>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top