I am using MVC. I want to pass the category data I entered from my view and passed to my Post/ Createcontroller, but it\'s not\'s letting me pass my categoryTypeID that I ha
I faced this error. I was binding an object of the View Model:
editPanelViewModel.Panel = new SelectList(panels, "PanelId", "PanelName");
In the View, I created the ListBox like this:
@Html.ListBoxFor(m => m.Panel, new SelectList(Model.Panel, "PanelId", "PanelName"))
It should be like this in fact:
@Html.ListBoxFor(m => m.Panel, new SelectList(Model.Panel, "Value", "Text"))
You are defining your SelectList
twice, in your controller as well as in your view.
Keep the view clean. Just the following would be enough in your case:
@Html.DropDownListFor(model => model.CategoryTypeID, (SelectList)ViewBag.CategoryTypes)
I have to admit that DropDownListFor is quite confusing in the beginning :)