【发布时间】:2019-07-04 10:10:20
【问题描述】:
我有这段代码可以在我以前的项目 asp.net core 2.0 和 2.2 中使用,它是一个带有自动回发功能的下拉列表
但是,在将它们添加到我最近的 3.0 项目中时,出现以下错误。这是我的代码和错误,请指教
谢谢
喂
错误信息
InvalidOperationException: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key "Cat"
显示所有类别 @Html.DropDownList("Cat", ViewBag.DepartmentID as IEnumerable, "显示所有部门", new { onchange = "form.submit();", @class= "form-control-textbox-dropdownlist" })
我的剃须刀视图页面
@Html.DropDownList("Cat", ViewBag.DepartmentID as IEnumerable<SelectListItem>, "Show all Departments", new { onchange = "form.submit();", @class = "form-control-textbox-dropdownlist" })
和控制器
ViewData["DepartmentID"] = new SelectList(_context.Set<Models.Department.Departments> (), "SubCategory_Name", "SubCategory_Name");
【问题讨论】:
标签: asp.net-core-mvc