DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'CategoryTypeID'

后端 未结 2 980
渐次进展
渐次进展 2021-01-04 03:42

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

相关标签:
2条回答
  • 2021-01-04 04:20

    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"))
    
    0 讨论(0)
  • 2021-01-04 04:30

    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 :)

    0 讨论(0)
提交回复
热议问题