
Untitled
By: a guest on
May 16th, 2012 | syntax:
None | size: 1.23 KB | hits: 13 | expires: Never
Creating a dropdownlist c# mvc3
<% List<string> foo = new List<string>();
foo.Add("Showing");
foo.Add("ComingSoon);"
foo.Add("Out");
Html.DropDownList(foo, Model.Status); %>
Html.DropDownList("Status",
new SelectListItem[]{ new SelectListItem{ Text= "Showing", Value="Showing"},
//same for others
});
<%: Html.DropDownListFor(model=> model.Status,
new List<SelectListItem>() {
new SelectListItem{ Text= "Showing", Value="Showing"},
new SelectListItem{ Text= "ComingSoon", Value="ComingSoon"},
new SelectListItem{ Text= "Out", Value="Out"}
}); %>
@{
List<KeyValuePair<int, string>> dropdownList =
new List<KeyValuePair<int, string>>();
dropdownList.Add(new KeyValuePair<int, string>(0,"Showing"));
dropdownList.Add(new KeyValuePair<int, string>(1,"ComingSoon"));
dropdownList.Add(new KeyValuePair<int, string>(2,"Out"));
SelectList selectList = new SelectList(dropdownList, "key", "value", 0);
}
@Html.DropDownList("foo", selectList)