Someone explain to me Html.DropDown and his dearest friend SelectList

If you check out my previous questions, you may have noticed that I just don't get SelectList and Html.DropDown (). It seems intriguing to me that I seem to be the only one in this. So maybe I should try to change my mindset, or maybe there are things that I don’t know that will clarify everything. I really like the whole MVC framework, but SelectList just doesn't want to fit into my head. So here is my list:

Selectlist

  • Why I can not set the selected value after creating the instance
  • Why can't I set selectedValue by element index
  • Why the selected value is sometimes a string, sometimes the class that I inserted into it, and sometimes ListItem
  • Why items are only accessible through GetItems ()
  • Why don't the selectedItem and listItems types match?
  • Why are the elements you put in the list converted to listItem and selectItem not?
  • Why can't I get the number of elements without using the GetItems () method

Html.DropDownList ()

  • Why does not binding to the model work with it.
  • Why there is no default behavior when there is only one parameter
  • Why doesn't the SelectedValue element in the source selectLIst element make it a marked element

Before ppl prompts me to write my own:
Since this will come with the MVC product, I would prefer official support for the basic control, and then minimize it myself and have all the problems that come with it.

+5
3

. , MvcFluentHtml. SelectList MultiSelectList, . .

+3

, HTML-, , SelectList. , , SelectList ( ) IEnumerable<T>. , , IEnumerable<T> ( LINQ/Entity Framework), , .

MvcFluentHtml ( MvcContrib) .

+2

, , , ! , MVC !

, , SelectList , :

<%= Html.DropDownList("Module.Status", new SelectList(ViewData.Model.Statuses, "ID", "Name", ((int)ViewData.Model.Module.Status)), new {tabindex = 1, title = "Status"})% >

ModelBinder ( , ? , , .)

public ActionResult Save(int? id, [Bind(Prefix = "Module", 
            Include = "Name,Description,Status")] Module module)

, - "module.Status".

+2

All Articles