On my application, I need to display some dropdownlist, linked to a display line.
<table>
<% foreach (var item in Model) { %>
<td>
<%= Html.Encode(item.COMPETENCE_LIBELLE) %>
</td>
<td>
<%= Html.DropDownListFor(item.FK_NIVEAU_ID, (SelectList)ViewData["FK_Niveau"]%>
</td>
<% } %>
</table>
However, I dont know why, the selected value of my ddlist is never displayed…
I havent got any problem to display the selected value of a single ddlist, but when its on a loop… I dont know what to do…
Any idea ?
If you need to display multiple dropdown lists then you might need to adapt your view model. So let’s take an example:
then have a controller action which will populate this view model:
and then have a corresponding strongly typed view:
and in the corresponding editor template (
~/Views/Shared/EditorTemplates/ItemsViewModel.ascx):