How to bind drop down in asp.net mvc 5
How to bind drop down in asp.net mvc 5 ?
Problem:
I have a web form, i want to show dropdown in that page, i want to fill the dropdown values from database.
Solution.
1-Code that will return list of user types from database.
var itemss = Model.GetBuyerTypesResult;
List<SelectListItem> myoptions=new List<SelectListItem>();
foreach (var item in itemss)
{
myoptions.Add(new SelectListItem { Value = item.userTypeID.ToString(), Text = item.userName });
}
2-Write code in html view as
@Html.DropDownList("CustomerType", (IEnumerable<SelectListItem>)myoptions)
Share This with your friend by choosing any social account