如何在mvc5中创建可搜索的下拉列表?

时间:2016-09-07 12:55:27

标签: javascript asp.net asp.net-mvc-5

我试图让我当前的下拉列表(由mvc搭建)可搜索。

我添加了这个脚本,但它没有帮助。

tableView height

这些是我的下拉列表

UITableView

1 个答案:

答案 0 :(得分:0)

<div class="form-group">
        @Html.LabelFor(model => model.VideoID, "VideoID", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("VideoID", null, htmlAttributes: new { @class = "form-control",@class="select2" })
            @Html.ValidationMessageFor(model => model.VideoID, "", new { @class = "text-danger" })
        </div>
    </div>

    

 <script type="text/javascript">
    $(document).ready(function() {
      $(".select2").select2();
    });
    </script>

<select class="js-example-basic-single">
  <option value="AL">Alabama</option>
    ...
  <option value="WY">Wyoming</option>
</select>