0
我有数据从一个电话回来在我的控制器下拉列表的集合,如下所示:如何投放自定义模式下拉列表为选择列表的
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>
}
我该如何正确地将收藏集转换回简单的下拉列表?
而不是将它转换为'List'试试将它转换成'YeagerTechModel.Status []'。数组实现IEnumerable,所以它应该很好地将它传递给'SelectList'。 –
asymptoticFault
非常感谢!这工作得很好:) – sagesky36
我怎么能给你这个积分? – sagesky36