我正在尝试将引导样式应用于以下下拉列表:
@Html.DropDownList("Scholarship_contactID", "-- Select Contact --", new { @class = "form-control"})
这会返回以下错误:
'System.Web.Mvc.HtmlHelper'不包含'DropDownList'的定义和最佳扩展方法重载'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper,string, System.Collections.Generic.IEnumerable,string)'有一些无效的参数
答案 0 :(得分:14)
您没有为下拉列表中的项目提供任何内容。
请注意这部分错误:
System.Collections.Generic.IEnumerable
..你错过了一个可用于项目的枚举。将您的代码更改为:
@Html.DropDownList("Scholarship_contactID",
new SelectList(new List<string>()),
"-- Select Contact --",
new { @class = "form-control"})
这使用以下重载:
public static MvcHtmlString DropDownList(
this HtmlHelper htmlHelper,
string name,
IEnumerable<SelectListItem> selectList,
string optionLabel,
object htmlAttributes
)