asp.net mvc - There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'xxx' -
There are some posts about this on the stack overflow, but there is no answer that started fixing the problem in my current state. Are there.
I have a table in it, each row has several text fields and a dropdown. All dropdowns need to use the same SelectList data, so I have set it as follows:
Controller
ViewData ["submarkets "] = New Selection List (Submarket Rip All Ordered ()," ID "," Name ");
View
& lt;% = html.DropDownList ("submarket_0", see the (selection list) data ["subway "]," (None) ")%>
I have actually used this setup in many places, but for some reason with this special point I get the error:
There is no visible data item type 'IEnumerable' whose key is 'submarket_0'.
OK, so the answer was received from some other posts about this problem And this is:
If your ViewData with a
SelectList
with your same name, your DropDownList
I.e. "submarket_0", HTML Assistant will automatically populate your data dropdownlist
if you do not specify 2 parameters which is the source in this case selection list.
What happened with my error:
Because the table with drop down list was in partial view and ViewData was changed and now In the
SelectList
was not referenced, HtmlHelper
(an error instead of throwing) tried to find the selectList called "submarket_0" in ViewData (GRRRR !!!), which it is now Could not even get it, and then threw an error on it :)
Please correct me if IM is wrong
Comments
Post a Comment