Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Somebody explain me Html.DropDown and it's dearest friend SelectList

If you check my earlier questions you may have noticed I just don't get the SelectList and Html.DropDown(). I find it intrigueing that I seem to be the only one in this. So maybe I should try to change my mindset or maybe there are things I don't know that will clear this all up. I really love the whole MVC framework, but SelectList just doesn't want to fit in my head. So here's my list:

SelectList

  • Why can't I set the selected value after instantiation
  • Why can't I set selectedValue by index of items
  • Why is the selectedvalue sometimes a string, sometimes the class I put into it and sometimes a ListItem
  • Why are the items only accesible through GetItems()
  • Why don't the types of selectedItem and the listItems match?
  • Why are the items you put in the list converted to listItem and the selectedItem not?
  • Why can't I get the count of the items without usint the GetItems() method

Html.DropDownList()

  • Why doesn't modelbinding work with it
  • Why is there no behaviour for defaulting selection when there's only one option
  • Why doesn't making an item SelectedValue in the source selectLIst make it the marked item

Before ppl suggest me to write my own:
Since this will be shipped with the MVC product, I would rather have the offical support for a basic controll then to roll my own and have all the troubles that come with it.

like image 386
Boris Callens Avatar asked Dec 03 '08 09:12

Boris Callens


1 Answers

I feel your pain. Forgive the shameless plug, but you might look into MvcFluentHtml. You can still use SelectList and MultiSelectList, but you have several other choices. Should work fine with binders.

like image 102
Tim Scott Avatar answered Oct 19 '22 22:10

Tim Scott