动态 MVC 多部门下拉列表
Dynamic MVC multisect dropdownlist
我正在尝试创建动态多选下拉列表。以下代码无效
<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 = "";
jQuery(result).each(function () {
solutionOptions += "<label><input type='checkbox' name='categories' value='" + this.Value + "'>" + this.Text + "</input></label>";
});
target.append(solutionOptions);
target.multiselect('rebuild')
这解决了我的问题:
jQuery("#SolutionList").multiselect('destroy');
jQuery("#SolutionList").multiselect();
jQuery(result).each(function () {
$("#SolutionList").append('<option value="' + this.Value + '">' + this.Text + '</option>').multiselect('rebuild');
});
下面link我解释如何使用bootstrap multi select
我正在尝试创建动态多选下拉列表。以下代码无效
<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 = "";
jQuery(result).each(function () {
solutionOptions += "<label><input type='checkbox' name='categories' value='" + this.Value + "'>" + this.Text + "</input></label>";
});
target.append(solutionOptions);
target.multiselect('rebuild')
这解决了我的问题:
jQuery("#SolutionList").multiselect('destroy');
jQuery("#SolutionList").multiselect();
jQuery(result).each(function () {
$("#SolutionList").append('<option value="' + this.Value + '">' + this.Text + '</option>').multiselect('rebuild');
});
下面link我解释如何使用bootstrap multi select