【问题标题】:Error.There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CategoryId'错误。没有“IEnumerable<SelectListItem>”类型的 ViewData 项具有键“CategoryId”
【发布时间】:2016-06-01 11:13:01
【问题描述】:

在视图下方出现错误:

@Html.DropDownList("CategoryId", null, "--Select--", new { @class = "form-control edited" })

【问题讨论】:

标签: asp.net-mvc-4


【解决方案1】:

因为您在 DropDownList 中将 selectList 应用为 null。下面一行会帮助你。

@Html.DropDownList("CategoryId", (new List<SelectListItem>()), "--Select--", new { @class = "form-control edited" })

这只是一个例子,你需要传递 List>() 的对象,如果它空白传递没有项目的对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 2020-06-28
    相关资源
    最近更新 更多