Html 没有类型为';IEnumerable<;选择列表项>';那有钥匙';CompPlanTypeId';

Html 没有类型为';IEnumerable<;选择列表项>';那有钥匙';CompPlanTypeId';,html,.net,viewbag,Html,.net,Viewbag,我不明白为什么会出差错。 如果我删除保存Comp Plan:的div标记,它就可以正常工作 <div id="tabs-1"> <form id="importForm"> <div id="required"> <div> <label class="OptionLabel">Comp Plan:</label>

我不明白为什么会出差错。 如果我删除保存Comp Plan:的div标记,它就可以正常工作

<div id="tabs-1"> 
    <form id="importForm">
        <div id="required">
            <div>
                <label class="OptionLabel">Comp Plan:</label>
                @*// TODO: suspect this next line is causing problems*@ 
                @Html.DropDownListFor(model => model.CompPlanTypeId, (IEnumerable<SelectListItem>)ViewBag.CompPlanList)
            </div>
            <div>
                <label class="OptionLabel">System:</label>
                @Html.DropDownListFor(model => model.SystemId, (IEnumerable<SelectListItem>)ViewBag.SystemList)
            </div>
            <div>
                <label class="OptionLabel">Month:</label>
                @Html.DropDownListFor(model => model.Month, (SelectList)ViewBag.MonthList)
            </div>
            <div>
                <label class="OptionLabel">Year:</label>
                @Html.DropDownListFor(model => model.Year, (SelectList)ViewBag.YearList)
            </div>
        </div>
ViewBag.CompPlanList设置为2项。一个包含空白字符串,一个包含下拉值

这是堆栈跟踪

[InvalidOperationException: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CompPlanTypeId'.]
[InvalidOperationException:没有具有键“CompPlantTypeId”的“IEnumerable”类型的ViewData项。]
System.Web.Mvc.Html.SelectExtensions.GetSelectData(HtmlHelper HtmlHelper,字符串名)+392896 System.Web.Mvc.Html.SelectExtensions.SelectInternal(HtmlHelper HtmlHelper、字符串选项标签、字符串名称、IEnumerable
1选择列表、布尔allowMultiple、IDictionary
2 htmlAttributes)+137 System.Web.Mvc.Html.SelectExtensions.DropDownListFor(HtmlHelper
1 HtmlHelper,Expression
1 Expression,IEnumerable
1选择列表,字符串选项标签,IDictionary
2 htmlAttributes)+35 System.Web.Mvc.Html.SelectExtensions.DropDownListFor(HtmlHelper
1 HtmlHelper,Expression
1 Expression,IEnumerable`1 selectList)+60 c:\WIP\CompensationAudit\src\WebLibrary\Views\Import\Index.cshtml:28中的ASP.\页面\视图\导入\索引\ cshtml.Execute()

[InvalidOperationException: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key 'CompPlanTypeId'.]