1. We have created a list of
SelectListItems inside the "BindingDropDown" method and passed it to the View. ssed it to the View.
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem
{
Text = "item1",
Value = "1"
});
items.Add(new SelectListItem
{
Text = "item2",
Value = "2"
});
ViewData["ListItems"] = items;
Binding Drop down at View
a. We can bind the dropdown list using html.Dropdownlist (it is a HTML helper class).
ListItems: <%= Html.DropDownList("ListItems")%>
Here we are passing "ListItems" that has been passed from the controller to the view.
b. Another overloaded method of the html.DropdownList class for binding a dropdown list.
<%= Html.DropDownList("SelectedItem", (IEnumerable<SelectListItem>)ViewData["ListItems"])%>
After run, u will get dropdown list with 2 items