将Bootstrap类应用于@ Html.DropDownList()

SRi*_*y22 7 c# asp.net asp.net-mvc asp.net-mvc-4 twitter-bootstrap-3

我正在尝试将引导样式应用于以下下拉列表:

@Html.DropDownList("Scholarship_contactID", "-- Select Contact --", new { @class = "form-control"})
Run Code Online (Sandbox Code Playgroud)

这将返回以下错误:

'System.Web.Mvc.HtmlHelper'不包含'DropDownList'的定义和最佳扩展方法重载'System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper,string,System.Collections) .Generic.IEnumerable,string)'有一些无效的参数

Sim*_*ead 15

您没有为下拉列表中的项目提供任何内容.

注意这部分错误:

System.Collections.Generic.IEnumerable

..你错过了一个可以用于物品的枚举.将您的代码更改为:

@Html.DropDownList("Scholarship_contactID", 
                   new SelectList(new List<string>()), 
                   "-- Select Contact --", 
                   new { @class = "form-control"})
Run Code Online (Sandbox Code Playgroud)

这使用以下重载:

public static MvcHtmlString DropDownList(
    this HtmlHelper htmlHelper,
    string name,
    IEnumerable<SelectListItem> selectList,
    string optionLabel,
    object htmlAttributes
)
Run Code Online (Sandbox Code Playgroud)