我试图用IEnumerable下拉式绑定数据库。但它显示在下面的图像中显示的错误。如何使用MVC5中的dropdownlist绑定数据库?
我的模型(CustomerViewModel)
public Nullable<System.Guid> AreaID { get; set; }
public string Area { get; set; }
public IEnumerable<SelectListItem> AreaList { get; set; }
我的控制器
public ActionResult Create()
{
CustomerViewModel cvm = new CustomerViewModel();
cvm.AreaList = db.Areas.Where(a => a.IsDeleted == false).Select(a => new SelectListItem()
{
Value = a.AreaID.ToString(),
Text = a.DisplayName
});
return View();
}
我查看代码
@Html.LabelFor(model => model.Area, new { @class = "control-label" })
@Html.DropDownListFor(m => m.AreaID, Model.AreaList, "Please select a Area", new { @class = "form-control" })
唯一的例外是相当清楚的。 **你认为这意味着什么? –
其实我不明白错误的意思,所以只有我在这里发表steen。 – Susan