Headaches with ASP.MVC UI Helpers

I’ve been beating my head against the UI helpers a lot lately and wanted to share a frustration point. Say I want to do something using the DropDownList, so you map a property on your page that returns a Select List:

<%= Html.DropDownList("db", SelectList)%>

publicstaticSelectList SelectList

{

get

{

List<ListItem> items = newList<ListItem>

{

newListItem {Selected = true, Text = "All", Value = ""},

newListItem {Text = "Apples", Value = "Ap"},

newListItem {Text = "Bananas", Value = "Bn"},

newListItem {Text = "Oranges", Value = "Or"}

};

returnnewSelectList(items);

}

}

Seems simple enough right? I’m giving the select list a list of ListItem. I’m using YOUR api. I don’t expect that THIS is what I get back:

Justification = "Operation performs conversions and returns a unique instance on each call.")]

publicvirtualIList<ListItem> GetListItems() {

return (!String.IsNullOrEmpty(DataValueField)) ?

GetListItemsWithValueField() :

GetListItemsWithoutValueField();

}

Perhaps a check to see if the items in the enumerable ARE already LISTITEM would be appropriate?

For the record, changing it to this makes the code work:

returnnewSelectList(items, "Value", "Text", items[0]);

But what happened to convention over configuration?

Edit: ok, the “correct” way I posted wasn’t actually correct. You can’t put the “Selected” item in the selectedValue field, you have to put the value there, in this case “Bn” or “Ap” etc. Heaven forbit putting the actual selected item as the parameter. Or pulling the selected item automatically from request values.