There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'xxx'.
Posted
by Jimbo
on Stack Overflow
See other posts from Stack Overflow
or by Jimbo
Published on 2010-05-17T13:22:59Z
Indexed on
2010/05/17
14:10 UTC
Read the original article
Hit count: 1699
There are a couple of posts about this on Stack Overflow but none with an answer that seem to fix the problem in my current situation.
I have a page with a table in it, each row has a number of text fields and a dropdown. All the dropdowns need to use the same SelectList data so I have set it up as follows:
Controller
ViewData["Submarkets"] = new SelectList(submarketRep.AllOrdered(), "id", "name");
View
<%= Html.DropDownList("submarket_0", (SelectList)ViewData["Submarkets"], "(none)") %>
I have used exactly this setup in many places, but for some reason in this particular view I get the error:
There is no ViewData item of type 'IEnumerable' that has the key 'submarket_0'.
© Stack Overflow or respective owner