【问题标题】:mvc dropdown list with bootstrap带引导程序的 mvc 下拉列表
【发布时间】:2016-08-19 19:18:17
【问题描述】:

我想要可搜索的下拉列表like this link

我正在使用 ASP.NET MVC

<td class="input">
    <select id="classLessonSelect">
        @foreach (Student student in Model) {
            <option value=@student.id>@student.Name @student.Surname</option>
        }
     </select>
</td>

我做不到,如何将它集成到我的代码中?

【问题讨论】:

  • 这类问题你需要一个小提琴

标签: jquery css asp.net asp.net-mvc twitter-bootstrap


【解决方案1】:

第一 您错过了tags 上的一些详细信息,其中一个是您的&lt;select&gt;&lt;/select&gt;selectpicker

应该像下面这样:

<td class="input">
    <select id="classLessonSelect" class="selectpicker" data-show-subtext="true" data-live-search="true">
        @foreach (var student in Model) {
            <option value=@student.id data-subtext="someSubText">@student.Name @student.Surname</option>
        }
     </select>
</td>

第二

你需要看看这个插件是否已经存在于你的项目中的BootStrap如果不是根据你发布的链接你需要这个http://silviomoreto.github.io/bootstrap-select/

【讨论】:

    【解决方案2】:

    当我需要带有多选选项的可搜索下拉菜单时,我使用了SumoSelect

    为此,我使用jQuery.Ajax 调用绑定数据以动态下拉。

    免责声明: 获取选定值等需要大量工作,因为这是基于 HTMLJavaScript,因此无法像传统 @ 那样在代码后面访问987654325@的下拉菜单。

    【讨论】:

      【解决方案3】:

      您是否考虑过使用像 Select2 https://select2.github.io/ 这样的插件。它有很多选项,其中一个是可搜索的选择。设置很容易,例如

      $("#selectId").select2();

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-27
        • 1970-01-01
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多