There is no ViewData item of type ‘IEnumerable’ that has the key ‘DropDownList’.

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 comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started