【问题标题】:Applying a Bootstrap class to @Html.DropDownList()将 Bootstrap 类应用于 @Html.DropDownList()
【发布时间】:2014-04-02 21:43:21
【问题描述】:

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

@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)' 有一些无效参数

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-mvc-4 twitter-bootstrap-3


    【解决方案1】:

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

    注意这部分错误:

    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
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多