Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. @model List<string>
  2. @Html.DropDownListFor(x => x)
  3.  
  4. @model List<string>
  5. @Html.DropDownList(
  6. "Foo",
  7. new SelectList(
  8. Model.Select(x => new { Value = x, Text = x }),
  9. "Value",
  10. "Text"
  11. )
  12. )
  13.  
  14. <select name="Foo" id="Foo">
  15. <option value="item 1">item 1</option>
  16. <option value="item 2">item 2</option>
  17. <option value="item 3">item 3</option>
  18. ...
  19. </select>
  20.  
  21. public class MyListModel
  22. {
  23. public string SelectedItemId { get; set; }
  24. public IEnumerable<SelectListItem> Items { get; set; }
  25. }
  26.  
  27. @model MyListModel
  28. @Html.DropDownListFor(
  29. x => x.SelectedItemId,
  30. new SelectList(Model.Items, "Value", "Text")
  31. )
  32.  
  33. List<string> ShipNames = new List<string>(){"A", "A B", "A B C"};
  34.  
  35. @Html.DropDownListFor(x => x.ShipNames, new SelectList(Model.ShipNames), "Select a Ship...", new { @style = "width:500px" })
  36.  
  37. <select id="ShipNames" name="ShipNames" style="width:500px">
  38. <option value="">Select a Ship...</option>
  39. <option>A</option>
  40. <option>A B</option>
  41. <option>A B C</option>
  42. </select>
  43.  
  44. yourRecord.FieldName = Request.Form["FieldNameInModel"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement