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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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

Blog at WordPress.com.

Up ↑

Create your website at WordPress.com
Get started
%d bloggers like this: