Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @model List<string>
- @Html.DropDownListFor(x => x)
- @model List<string>
- @Html.DropDownList(
- "Foo",
- new SelectList(
- Model.Select(x => new { Value = x, Text = x }),
- "Value",
- "Text"
- )
- )
- <select name="Foo" id="Foo">
- <option value="item 1">item 1</option>
- <option value="item 2">item 2</option>
- <option value="item 3">item 3</option>
- ...
- </select>
- public class MyListModel
- {
- public string SelectedItemId { get; set; }
- public IEnumerable<SelectListItem> Items { get; set; }
- }
- @model MyListModel
- @Html.DropDownListFor(
- x => x.SelectedItemId,
- new SelectList(Model.Items, "Value", "Text")
- )
- List<string> ShipNames = new List<string>(){"A", "A B", "A B C"};
- @Html.DropDownListFor(x => x.ShipNames, new SelectList(Model.ShipNames), "Select a Ship...", new { @style = "width:500px" })
- <select id="ShipNames" name="ShipNames" style="width:500px">
- <option value="">Select a Ship...</option>
- <option>A</option>
- <option>A B</option>
- <option>A B C</option>
- </select>
- yourRecord.FieldName = Request.Form["FieldNameInModel"];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement