I'm using this code to generate a multi-select2. Tags is a MultiSelectList.
@Html.DropDownList("mail-to", (IEnumerable<SelectListItem>)ViewBag.Tags, String.Empty, htmlAttributes: new { multiple = "", @class = "form-control select2 select2-multiple" })
$("#mail-to").select2({
minimumResultsForSearch: -1,
closeOnSelect: false,
});
It works great. Now I want to change the select options with another ViewBag based on a checkbox field checked change event. Is there a way to change select2 data populated with this type of list or a MVC way to do it?
What I've tryed:
$("#mail-to").select2({
tags: @ViewBag.TagsArea, //or tags: @Html.Raw((IEnumerable<SelectListItem>)ViewBag.TagsArea)
});