Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
igcombo multi-select mvc model binding issue
posted

Hello,

I'm having issues getting a multichoice igcombo to bind correctly to my mvc model.

- Model -

public class GroupsModel
{
public Guid GroupID { get; set; }
public List<Guid> Users { get; set; }
}

- View -

@using Infragistics.Web.Mvc;

@model List<GroupsModel>

<table class="table table-striped table-condensed">
<tr><th>Users</th></tr>
@for (var recordIndex = 0; recordIndex < Model.Count(); recordIndex++)
{
<tr>
<td>
@(Html.Infragistics().ComboFor(m => m[recordIndex].Users)
.Width("400")
.VisibleItemsCount(4)
.MultiSelectionSettings(msc =>
{
msc.ShowCheckBoxes(true);
msc.Enabled(true);
msc.ItemSeparator(",");
})
.DataSource(ViewBag.AllContacts)
.TextKey("Name")
.ValueKey("userID")
.DataBind()
.Render())
</td>
</tr>
}
</table>

- Controller -

[HttpPost]
public async Task<IActionResult> SaveGroups(List<GroupsModel> groups, string returnUrl = null)
{
//groups[0].Users.Count() == 0
}


For each group the users list will be empty in the model.

HttpContext.Request.Form["[0].Users"] contains a comma delimited list of Guids, which I can work with, but would prefer not to (if I don't have to).

However, replacing Infragistics.ComboFor with @Html.ListBoxFor(m => m[recordIndex].Users, new MultiSelectList(ViewBag.AllContacts, "userID", "Name")) will properly bind to the model, so I'm not sure what I'm missing when setting up the igcombo editor.

Thanks!

Parents
  • 2680
    Verified Answer
    Offline posted

    Hello Jarrod,

    Thank you for contacting us.

    The issue is your ids should start with a letter - HTML standard. You could just add ids to the wrapper:

     @(Html.Infragistics().ComboFor(m => m[recordIndex].Users)
                         .ID("combo" + (recordIndex + 1))...

    Please make the Users list a string, after that you could use string split by comma.

    I am attaching a sample demonstrating the working combo.

    Please let me know if you need further assistance.

    MultiSelectionCombo.zip
Reply Children
No Data