igCombo multiselect binding

Not Answered This post has 0 verified answers | 2 Replies | 2 Followers Thread's RSS feed.

redox
Points 1,865
Replied On: Thu, Oct 12 2017 7:08 AM Reply

I'm defining a combo as follows:

          @(Html.Infragistics().ComboFor(model => model.SelectedRoleIdsString)
                    .MultiSelectionSettings(msc =>
                    {
                      msc.ShowCheckBoxes(true);
                      msc.Enabled(true);
                      msc.ItemSeparator(",");
                    })
                    .DataSource(Model.AvailableRoleNames)
                    .TextKey("Text")
                    .ValueKey("Value")
                    .DataBind()
                    .Render()
          )
Originally I started off with SelectedRoleIds defined as an array of integers, but this didn't cause the existing values to be selected in the combo.  Then I changed SelectedRoleIds to be a comma separated string and that still didn't work and then finally I changed it to an array of strings and now the existing selected roles are shown in the text area when the page loads.  So, for example, if I set the values as follows it works:

SelectedRoleIdsString = new string[] {"1", "2"};

However, if I update the selection in the combo control, it appears that the selected values are then returned in a single element string array with all of the values put into a comma separated string in the first element of the array: https://imgur.com/a/fZ6ap  I.e. the format required for getting the data to display is different to the format that is then submitted back?
Is this right, and if so why does it work like that and where is this discussed in the documentation?
Thanks, Tom
  • Post Points: 20

All Replies

[Infragistics]Mike P
Points 24,360
Infragistics Employee
Replied On: Thu, Oct 12 2017 3:25 PM Reply

Hello Tom,

Thank you for contacting Infragistics!

What method are you using to get the selected items, if you use the “selectedItems” method it returns and array where each item contains the data and the html element:

https://www.igniteui.com/help/api/2017.1/ui.igcombo#methods:selectedItems

Whereas if you use “value” it returns the values in an array with each item as their own string:
https://www.igniteui.com/help/api/2017.1/ui.igcombo#methods:value

Sincerely,
Mike P.
Software Developer
Infragistics, Inc.
www.infragistics.com

  • Post Points: 20
redox
Points 1,865
Replied On: Sat, Oct 14 2017 5:14 AM Reply

Hi Mike

I'm not using either, it's on an MVC form, so the HTML for the controls is wrapped in:

@using (Html.BeginForm("Edit", "Users", FormMethod.Post, new { role = "form", id = "create-update-form", autocomplete = "off" }))
{
    ....
}
  • Post Points: 5
Page 1 of 1 (3 items) | RSS