I have a number of Html.Listbox controls on my view which are being populated by an IEnumberable<SelectListItem>
Is there a way that when the data is populated, that some items are automatically selected?
The particular selectlist items in the IEnumerable are marked as Selected = true, yet this does not convey into the view.
The view is as such:
<%= Html.ListBox("projects", Model.Projects)%>
Thanks.
Best Answer
Sure as always you start by defining a view model that will represent the information you would like to show on the particular view:
then a controller:
and finally in your strongly typed view:
As expected Item 1 and Item 3 will be preselected when the list box is rendered.