problem with multi selectbox with kendoMultiSelect, the selected values are not showing.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
THe below problem is really driving me nuts from last6 hrs.

I am trying to have a multiselect dropdown box for my view

<div class="col-md-6">
                                
                                @Html.EditorFor(model => model.SelectedCategoryIds, new { SelectList = Model.AvailableCategories })                              
                                <script>
                                    $(document).ready(function() {
                                        var storesIdsInput = $('#@Html.FieldIdFor(model => model.SelectedCategoryIds)').data("kendoMultiSelect");
                                        storesIdsInput.setOptions({
                                            autoClose: false
                                        });

                                        @if (Model.AvailableCategories.Count == 0)
                                    {
                                        <text>
                                        storesIdsInput.setOptions({
                                            enable: false,
                                            placeholder: 'No stores available'
                                        });
                                        storesIdsInput._placeholder();
                                        storesIdsInput._enable();
                                        </text>
                                    }
                                    });
                                </script>
                                
                            </div>


where my model properties are like :

[UIHint("MultiSelect")]
        public IList<int> SelectedCategoryIds { get; set; }

        public IList<SelectListItem> AvailableCategories { get; set; }


the problem is in the view it is generating the multiselect dropdown box but the selected items are not set in that, it is always blank


When i use a ListBoxFor and i can see that the data is been set and it sets selected items  
@Html.ListBoxFor(model => model.SelectedCategoryIds, new MultiSelectList(Model.AvailableCategories, "Value", "Text"), null)
7 years ago
Hope below urls will help you
https://www.nuget.org/packages/MvcCheckBoxList/
http://www.c-sharpcorner.com/UploadFile/f7f45a/checkboxlist-in-mvc/
7 years ago
Ohhh.. my bad ..while building the SelectListItems i forgot to set Selected property
Selected = model.SelectedCategoryIds.Contains(s.Id)



var categories = _categoryService.GetAllCategories().Select(s => new SelectListItem
            {
                Text = s.Name,
                Value = s.Id.ToString(),
                Selected = model.SelectedCategoryIds.Contains(s.Id)
            }).ToList();
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.