This is a migrated thread and some comments may be shown as answers.

MultiSelectFor in Popup edit template can only remove objects

1 Answer 59 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Sebastian
Top achievements
Rank 1
Sebastian asked on 05 Oct 2018, 02:21 PM

I have a grid where i have popup edit enabled. For this popup editing i have a template and in the template i have a multiselectfor which looks like this:

 

 @(Html.Kendo().MultiSelectFor(x => x.SelectedConsultantIds)
                                              .AutoClose(false)
                                              .Placeholder("Select consultants")
                                              .DataTextField("DisplayName")
                                              .DataValueField("Id")
                                              .IgnoreCase(true)
                                              .Filter("contains")
                                              .DataSource(source =>
                                              {
                                                  source.Read(read =>
                                                  {
                                                      read.Action("GetAvailableConsultants", "Project");
                                                  });
                                              })
                      )

 

 

When i load the grid the SelectedConsultantIds (List<string>) is populated for each item. I then click Edit for a row and the multiselectfor loads with all the DisplayNames preselected. However when i add new items to the multiselect from the selection they do not get added to the SelectedConsultantIds list when i click update and watch the viewmodel in the controller. The list stays the same if i only add. It does seem to update when i remove items from the list and click update.

So i can only remove items and not add items in this multiselect. The items get added and removed in the box itself, but not when i pass the viewmodel with the list to the controller.

 

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 10 Oct 2018, 08:59 AM
Hi Sebastian,

In order to properly select new items, you will need to specify that the MultiSelect widget works with primitive values (the Ids). To do that you should set its ​ValuePrimitive() ​configuration method to ​true:
@(Html.Kendo().MultiSelectFor(x => x.SelectedConsultantIds)
    .AutoClose(false)
    .Placeholder("Select consultants")
    .DataTextField("DisplayName")
    .ValuePrimitive(true)
    .DataValueField("Id")
    .IgnoreCase(true)
    .Filter("contains")
    .DataSource(source =>
    {
        source.Read(read =>
        {
            read.Action("GetAvailableConsultants", "Home");
        });
    })
)

Attached you will find a small sample implementing the above suggestion.

I hope that the above helps you. Should you have any other questions, please do not hesitate to contact us.

Regards,
Veselin Tsvetanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
MultiSelect
Asked by
Sebastian
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or