MultiSelect modelbinding in a loop and form post

4 posts, 0 answers
  1. erwin
    erwin avatar
    382 posts
    Member since:
    Dec 2006

    Posted 27 Aug 2017 Link to this post


    I have a list of objects in my model

       public class SoftwareItemPropertiesViewModel
            public List<Annotation> Annotations { get; set; } = new List<Annotation>();


    that I render to multiple multiselect like so:

    for (var i = 0; i < Model.Annotations.Count; i++)
              <div class="form-group">               
                  <div class="col-sm-10">
                      @(Html.Kendo().MultiSelectFor(m => m.Annotations[i].SelectedOptions)


    On post of the form, I can see that the selected data is there as as expected in Annotations[0].SelectedOptions:

    Annotations%5B0%5D.SelectedOptions: 4
    Annotations%5B0%5D.SelectedOptions: 5
    Cost: 515
    Description: adfasdf
    Guid: 40f339ed-b1e8-4a46-a987-8d5d79ec0be0
    Name: abcasdfsadf
    SelectedOwners: 1
    SelectedOwners: 2


    However, the selected Values are not populated back in the Model object that I receive.

    Annotations List is populated with 1 Annotation as expected, but Annotations[0].SelectedOptions is not populated.

    There is another Multiselect directly bound to the model and here I see Selected values in the model as expected.

    What am I missing?

    Regards Erwin


  2. erwin
    erwin avatar
    382 posts
    Member since:
    Dec 2006

    Posted 27 Aug 2017 in reply to erwin Link to this post

    Never mind. Missed the obvious.

    Annotations[]SelectedOptions needs to be a public Property. A Public field does not work but also raises no errors with the compiler nor the model binder.



  3. Dimitar
    Dimitar avatar
    352 posts

    Posted 29 Aug 2017 Link to this post

    Hello Erwin,

    I have reviewed the provided configuration and it looks valid. You are also correct that selectedOption need to be a public property in order for the binding to work.

    Can you confirm if you managed to successfully resolve the issue with this modification?

    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  4. erwin
    erwin avatar
    382 posts
    Member since:
    Dec 2006

    Posted 29 Aug 2017 in reply to Dimitar Link to this post

    Hi Dimitar,

    sorry if I was unclear in my last message. Changing from public Field to public Property enabled the Binding and everything works as expected now.

    What I find a bit confusing is that referencing a public field works in the View but cannot be populated by the standard model binder. But that is standard ASP.NET behaviour, nothing specific to Telerik.






Back to Top