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

我正在尝试将引导样式应用于以下下拉列表:
@Html.DropDownList("Scholarship_contactID","-- Select Contact --",new { @class = "form-control"})

这将返回以下错误

‘System.Web.Mvc.HtmlHelper’ does not contain a deFinition for ‘DropDownList’ and the best extension method overload ‘System.Web.Mvc.Html.SelectExtensions.DropDownList(System.Web.Mvc.HtmlHelper,string,System.Collections.Generic.IEnumerable,string)’ has some invalid arguments

解决方法

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

注意这部分错误

System.Collections.Generic.IEnumerable

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

@Html.DropDownList("Scholarship_contactID",new SelectList(new List<string>()),new { @class = "form-control"})

这使用以下重载:

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

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...