我有一个从我的控制器中调用下拉列表返回的数据集合,如下所示:
ViewData["statuses"] = db.GetStatuses();
它的类型为“YeagerTechModel.Status[]”。
当我尝试在一个简单的下拉列表中的视图中列出该数据时,出现以下错误:
Exception Details: System.InvalidCastException: Unable to cast object of type 'YeagerTechModel.Status[]' to type 'System.Collections.Generic.List`1[YeagerTechModel.Status[]]'
我的视图设置如下:
@using (Html.BeginForm("AddSingleStatus", "Status", new AjaxOptions { HttpMethod = "POST", }))
{
@Html.ValidationSummary(true)
<table>
<tr>
<td>
<div class="display-label">
@Html.LabelFor(model => Model.Description);
</div>
<div class="editor-field">
@Html.DropDownListFor(model => Model.Description, new SelectList((List<YeagerTechModel.Status[]>)ViewData["statuses"], "StatusID", "Description"));
@Html.ValidationMessageFor(model => Model.Description)
</div>
</td>
</tr>
<tr>
<td>
<input type="submit" value='@Resources.Add' />
</td>
</tr>
</table>
}
如何正确地将集合重新转换为简单的下拉列表?