MultiSelectFor in Popup edit template can only remove objects

2 posts, 0 answers
  1. Sebastian
    Sebastian avatar
    6 posts
    Member since:
    Aug 2018

    Posted 05 Oct 2018 Link to this post

    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.

     

  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1127 posts

    Posted 10 Oct 2018 Link to this post

    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.
Back to Top