0

Never work on ASP.NET MVC before. I'm using davidstutz/bootstrap-multiselect. In my view are some @Html.DropDownListFor elements, which needs to create filter to db. I can deselect all after refresh, but I can't save users choice after refresh. Can someone give me any advice?

@Html.DropDownListFor(m => m.KvedFilter, new SelectList(ViewBag.KvedsFilter), new { @class = "form-control dd", @id = "dropDownKved", @multiple = "multiple" })

Found script which as I understand get values of selected item

<script type="text/javascript">
    $(function () {
        $('[id*=dropDownKved]').multiselect({
            includeSelectAllOption: false,
            numberDisplayed: 1,
            buttonWidth: '100%',
            onChange: function (element, checked) {
                var brands = $('[id*=dropDownKved]');
                var selected = [];
                $(brands).each(function (index, brand) {
                    selected.push([$(this).val()]);
                });

                console.log(selected);
            }
        });
    });
</script>
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Hello. If you post your code and show what you've done so far then I'm sure someone will assist. – Wheels73 Jan 23 '18 at 15:56
  • You need to post your view so we can see how you are rendering your page... and also the controller so we can see how the view is returned and also the Save method that you post too when saving. – Wheels73 Jan 23 '18 at 16:11
  • Its ot clear what your asking or what your issue is, but you need to remove `@multiple = "multiple"` and use `ListBoxFor()` - refer [this answer](https://stackoverflow.com/questions/40725358/why-does-the-dropdownlistfor-lose-the-multiple-selection-after-submit-but-the-li/40732481#40732481) –  Jan 23 '18 at 21:00
  • [Solution is here](https://stackoverflow.com/questions/40725358/why-does-the-dropdownlistfor-lose-the-multiple-selection-after-submit-but-the-li/40732481#40732481), thanks to Stephen Muecke! – Ihor Mykytiv Jan 24 '18 at 07:16

0 Answers0