I am trying to populate a dropdown list from a database mapped with Linq-2-SQL, using ASP.NET MVC 2, and keep getting this error.
I am so confused because I am decla
If you use Html.DropDownList()
method - same error may occur, if your ViewData/Viewbag item not set, as @Peto answered.
But it may be not set in case of controller set item correctly, but in main view you use partial viw call with new ViewDataDictionary values.
if you have @Html.Partial("Partianame", Model,new ViewDataDictionary() { /* ... */ })
then your partial view will not see ViewData
and ViewBag
data, remove new ViewDataDictionary()
parameter