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'.
The problem is because of post back happens on submit button click. So while posting data on submit click again write before returning View()
In my case there was a conflict in the namespaces , I have:
and
I explicitly want to use the Mvc one so I declared it as :