问题
I am using Multiple Select2 plugin in an user registraion page.On clicking the submit button,after the details are saved i am resetting the dropdownlist.The problem is that when i select another item from the dropdownlist a blank item
is automatically selected in the dropdownlist
Html
@Html.DropDownListFor(m => m.MultipleCourseId
, Model.MultipleCourseList
, ""
, new { @class = "form-control select2", @id = "ddlCourseMultiple",@multiple="multiple" })
Calling reset on Jquery Button click
$(document).on("click", "#btnCancel", clearAll);
//clear all controls
var clearAll = function () {
$(".form-control").val('');
//resetting dpdwn for clearing the selected option
$("#ddlCourseMultiple").select2("val", "");
return false;
};
回答1:
You could try this :
$("#ddlCourseMultiple").val(null).trigger("change");
来源:https://stackoverflow.com/questions/33119938/resetting-jquery-select2-multiple-dropdownlist-causes-a-blank-item-to-be-selecte