我正在使用MultiSelectList创建一个ListBoxFor,但是我收到以下错误:DataBinding: *.Models.Facilities does not contain a property with the name FacilitiesList.
以下是我的观点:
@model *.Models.Reservation
<div class="form-group">
@Html.LabelFor(model => model.FacilitiesList, "Facilities", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.ListBoxFor(model => model.FacilitiesList, ViewBag.FacilitiesList as MultiSelectList, htmlAttributes: new { @class = "form-control" })
</div>
</div>
viewbag FacilitiesList填充如下:
public ActionResult Create()
{
ViewBag.FacilitiesList = new SelectList(_facilityrepository.GetAll(), "FacilitiesList", "FacilityType");
return View();
}
答案 0 :(得分:0)
解决了它。简单的解决方案:
我改变了这个:
ViewBag.FacilitiesList = new SelectList(_facilityrepository.GetAll(), "FacilitiesList", "FacilityType");
到此:
ViewBag.FacilitiesList = new SelectList(_facilityrepository.GetAll(), "FacilityId", "FacilityType");