1.先创建SelectList
IList<SelectListItem> dict = new List<SelectListItem>();
List<SupplierInfo> list = context.SupplierInfoes.Where(model=>model.IsUse== 1).ToList();
list.ForEach(u => dict.Add(new SelectListItem { Text = u.SupplierName, Value = u.Id.ToString() }));
ViewData["SupplierId"] = new SelectList(dict , "Value", "Text");
2绑定,绑定
@Html.DropDownListFor(model=>model.SupplierId, ViewData["SupplierId"] as SelectList)
3.当时显示没有错误,保存老报这行有错,发现当传过来的是强类型数据时候,删除了一个字段
就报错,添加了所有的字段就不会出现错