Solution
In Controller
ViewData["DropDownList"] = clsChargesCollection.FillInstallments().Select(x => new SelectListItem { Text = x.Description, Value = x.ID.ToString() }).ToList();
Syntax
ViewData[“name to be given”]=db.MethodName.Select(object => new SelectListItem{Text = object.columnName, Value = object.columnName.ToString()}.ToList();
In View:
Try to access the variable within the top of your View where titles are given
@{
List <SelectListItem> MemIds = ViewData["DropDownlist"] as List<SelectListItem>;
}
Now, Where you created DropDown:
@Html.DropDownList("DropDownList", MemIds, "--Select Membership ID--")
Leave a Reply