Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.23 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Creating a dropdownlist c# mvc3
  2. <% List<string> foo = new List<string>();
  3.    foo.Add("Showing");
  4.    foo.Add("ComingSoon);"
  5.    foo.Add("Out");
  6.  
  7.    Html.DropDownList(foo, Model.Status); %>
  8.        
  9. Html.DropDownList("Status",
  10.     new SelectListItem[]{ new SelectListItem{ Text= "Showing", Value="Showing"},
  11.     //same for others
  12. });
  13.        
  14. <%: Html.DropDownListFor(model=> model.Status,
  15.                          new List<SelectListItem>() {
  16.                                 new SelectListItem{ Text= "Showing", Value="Showing"},
  17.                                 new SelectListItem{ Text= "ComingSoon", Value="ComingSoon"},
  18.                                 new SelectListItem{ Text= "Out", Value="Out"}
  19.                          }); %>
  20.        
  21. @{          
  22.     List<KeyValuePair<int, string>> dropdownList =
  23.                                                         new List<KeyValuePair<int, string>>();
  24.                 dropdownList.Add(new KeyValuePair<int, string>(0,"Showing"));
  25.                 dropdownList.Add(new KeyValuePair<int, string>(1,"ComingSoon"));
  26.                 dropdownList.Add(new KeyValuePair<int, string>(2,"Out"));
  27.                 SelectList selectList = new SelectList(dropdownList, "key", "value", 0);
  28.  
  29. }
  30.  
  31. @Html.DropDownList("foo", selectList)