Reputation: 752
I am not able to get Kendo UI Multiselect's value in controller. it gives me length of list as 0. MultiSelect is as:
@(Html.Kendo().MultiSelectFor(model => model.Technicians)
.Name("Technicians")
.Placeholder("Select Technician(s)")
.DataTextField("Name")
.DataValueField("ID")
.Filter(FilterType.Contains)
.AutoBind(true)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetTechnicians", "Project");
})
.ServerFiltering(false);
})
.BindTo(Model.Technicians)
)
Technicians is : public List Technicians{get; set;} in model
Upvotes: 3
Views: 1459
Reputation: 51
I ran into this problem as well.
We ended up creating an IEnumerable<int>
of Ids in the viewmodel to store that value.
So, in our instance
public IEnumerable<PersonLookupViewModel> TaggedPersons { get; set; }
(this is the list of people with IDs that I really want - contains first/last/id)
public IEnumerable<int> PeopleToTag { get; set; }
(this is the IEnumerable Int of the view model solely for posting the ints to the controller)
My view looked like this:
<div class="editor-field">
@Html.LabelFor(model => model.taggedPersons)
@Html.ListBoxFor(model => model.PeopleToTag,
new SelectList(Model.CommitteeMembers, "PersonId", "FullName"))
</div>
and the JS wire up
$("#PeopleToTag").kendoMultiSelect({ "dataTextField": "FullName", "dataValueField": "PersonId", "placeholder": "Tag or Untag Persons to Action Item" });
So switching it to a ListBoxFor(model = > model.PeopleToTag) which was my Ienumerable field in my viewmodel solely to be able to get the data in the controller. I then used automapper to create the Person model I actually needed.
I'm not sure if this is the best way, but it worked for us.
Upvotes: 1