【发布时间】:2015-02-28 17:17:45
【问题描述】:
更新:
因为我的DropDownTypes 是一个集合,所以我尝试传递这样的内容:它可以工作,但我遇到的唯一问题是它选择的默认值是 0 和我的item.Type 的索引是选中的值
@Html.DropDownListFor(m => item.Type, new SelectList(item.DropDownTypes.Select(x => x.Text)))
我在这里做错了什么,我正在尝试加载下拉列表
'System.Web.Mvc.HtmlHelper>' 不包含“DropDownList”的定义和最好的 扩展方法重载 'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper, 细绳, System.Collections.Generic.IEnumerable, object)' 有一些无效参数
@model IEnumerable<web.Models.CollectionViewModel>
@foreach (var item in Model )
{
<tr>
<td>
@Html.DropDownList(item.DropDownTypes, (IEnumerable<SelectListItem>)ViewBag.DropDownLoadRecoveryType, new { @class = "form-control" })
</td>
</tr>
}
【问题讨论】:
-
您有很多问题 - 您不能在循环中使用
DropDownListFor(),除非您生成新的SelectList并在每次迭代中设置选定的值,或者使用自定义EditorTemplate模型并将SelectList作为附加视图数据传递。你能发布模型和GET方法吗