更新:
因为它的myDropDownTypes
是一个集合,所以我尝试传递类似的内容:它可以工作,但是我唯一的问题是它选择默认值,该默认值与0的索引相同,而myitem.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,字符串,系统。 Collections.Generic.IEnumerable,对象)'有一些无效的参数
@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>
}
万一其他人需要知道,这就是我能够达到的解决方案。
@Html.DropDownListFor(model => item.Type.Value, new SelectList(ViewBag.DropDownLoadRecoveryType, "Value", "Text", item.Type))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句