Serialize MVC MultiSelect as array

4 posts, 1 answers
  1. 100%
    100% avatar
    75 posts
    Member since:
    Apr 2013

    Posted 11 Oct 2013 Link to this post

    I have this Kendo UI multiselect:

    @(Html.Kendo().MultiSelect()
          .Name("EditModel.Modules.ID")
          .DataValueField("ID")
          .DataTextField("Name")
          .Filter(FilterType.Contains)
          .DataSource(source =>
          {
            source.Read(read =>
                        {
                        read.Action("GetModules", "Modules");
                        })
                       .ServerFiltering(true);
                        }))

    How can I add [index] to name so the array maps to the array in my editmodel?

    Is there some setting that would add [x] automatically to the name?

    /Lasse
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 11 Oct 2013 Link to this post

    Hello Hans,

     Did you try my suggestion from stackoverflow?

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. 100%
    100% avatar
    75 posts
    Member since:
    Apr 2013

    Posted 14 Oct 2013 Link to this post

    @(Html.Kendo().MultiSelectFor(m => m.EditModel.ModulesSite)   // can't access property
          .DataValueField("ID")
          .DataTextField("Name")
          .Filter(FilterType.Contains)
          .DataSource(source =>
          {
            source.Read(read =>
                        {
                        read.Action("GetModules", "Modules");
                        })
                       .ServerFiltering(true);
                        }))
    I changed to this code but can't access the property "ID" in the ModulesSite-navigation property. What's needed to be changed? ModulesSite is a List< Module> that has int "ID" and string "Name".
  5. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Oct 2013 Link to this post

    Hi Hans,

    The MultiSelect value won't be posted as a collection of your type. Only the value property ("Name" in your case) will be posted. Basically it behaves exactly as the <select multiple> element. Perhaps the following resources would turn up useful:
    http://stackoverflow.com/questions/1255472/how-does-a-multiple-select-list-work-with-model-binding-in-asp-net-mvc
    http://ittecture.wordpress.com/2009/04/30/tip-of-the-day-198-asp-net-mvc-listbox-controls/

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready