I have an ASP.Net MVC view which inherits from a ViewModel. The ViewModel contains data from two entities in the model:
public PaginatedList<Entry> Entries { get; private set; }
public SelectList ColumnValues { get; private set; }
These two properties are used on the view, which is based on a list template.
The list iterates through the Entries list and displays a table row for each of them. Within one of the table cells in the row is a DropDownList populated from the ColumnValues propery from the ViewModel.
I can get the DropDownList to set it’s selected item using the following:
@Html.DropDownList("ColumnValue", Model.ColumnValues)
This renders the page, each row with a DropDownList in one of the cells. However the selected value is always set to the ‘ColumnValue’ for the first row, and is like this for all of the rows.
How would I go about modifying my code so that the selected value of the DropDownList matches the ColumnValue for each inividual entry.
The aim is to produce a kind of editable datagrid with links to post back the changes per row using AJAX.
Using DropDownListFor() in the View and setting the selectList to the following works:
This doesn’t seem to be a great way of doing things, but it works. And that’s the most important thing right now. Any further comments would be appreciated.