This is a migrated thread and some comments may be shown as answers.

Serialize MVC MultiSelect as array

3 Answers 360 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
100%
Top achievements
Rank 1
100% asked on 11 Oct 2013, 08:13 AM
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

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Oct 2013, 02:29 PM
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!
0
100%
Top achievements
Rank 1
answered on 14 Oct 2013, 07:42 AM
@(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".
0
Accepted
Atanas Korchev
Telerik team
answered on 14 Oct 2013, 07:49 AM
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!
Tags
MultiSelect
Asked by
100%
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
100%
Top achievements
Rank 1
Share this question
or