MVC dropdownListFor 绑定错误
model:
public class 培训中心
{
[Key]
public Guid 中心标识 { get; set; }
public string 中心名称 { get; set; }
public virtual List<科室> 科室s { get; set; }
}
public class 科室
{
[Key]
public Guid 科室标识 { get; set; }
public Guid 中心标识 { get; set; }
public string 科室名称 { get; set; }
}
生成中心list
public List<SelectListItem> GetEduCenters()
{
ChildEduDbContext db = new ChildEduDbContext();
var quert = db.Centers;
List<SelectListItem> item = new List<SelectListItem>();
foreach (var it in quert)
{
item.Add(new SelectListItem { Text = it.中心名称, Value = it.中心标识.ToString() });
}
return item;
}
绑定
@Html.DropDownListFor(model => model.中心标识.ToString(), ViewData["中心"] as SelectListItem)
错误提示
Compiler Error Message: CS1928: 'System.Web.Mvc.HtmlHelper<ChildEdu.Models.科室>' does not contain a definition for 'DropDownListFor' and the best extension method overload 'System.Web.Mvc.Html.SelectExtensions.DropDownListFor<TModel,TProperty>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TProperty>>, System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)' has some invalid arguments