动态MVC多扇区下拉列表

时间:2017-04-04 21:10:56

标签: javascript jquery asp.net-mvc bootstrap-multiselect

我正在尝试创建动态多选下拉列表。以下代码无效

  <div class="form-group">
            @Html.Label("Solutions", htmlAttributes: new { @class = "control-label col-md-4" })
            <div class="col-md-8">
                @Html.DropDownListFor(model => model.SolutionList, new SelectList(new List<SelectListItem>(), "Value", "Text"), new { multiple = "true", @class = "form-control list-group-active-color", Style = "width:100% !important", onchange = "OnGetSolutionsChange(this)" })
                @Html.ValidationMessageFor(model => model.SolutionList, "", new { @class = "text-danger" })
            </div>
        </div>

var solutionOptions =&#34;&#34 ;;

    jQuery(result).each(function () {
        solutionOptions += "<label><input type='checkbox' name='categories' value='" + this.Value + "'>" + this.Text + "</input></label>";          
    });       
    target.append(solutionOptions);
    target.multiselect('rebuild')

2 个答案:

答案 0 :(得分:0)

这解决了我的问题:

jQuery("#SolutionList").multiselect('destroy');
jQuery("#SolutionList").multiselect();

    jQuery(result).each(function () {
       $("#SolutionList").append('<option value="' + this.Value + '">' + this.Text + '</option>').multiselect('rebuild');
    });    

答案 1 :(得分:0)

下面链接我解释了如何使用bootstrap multi select

enter link description here

相关问题