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

Cannot set initial values from viewmodel

1 Answer 46 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Mac P
Top achievements
Rank 1
Mac P asked on 18 Mar 2014, 03:27 AM
Hello,

When i bind the Multiselect list to ViewBag the list renders fine. However the "Values" property never gets set. I have tried with IEnumerable object as well as list<string> or string[] of ids. I cannot find any help online. When i post the viewmodel does post selected values. 
I have also played with Autobind true and false

Here is the code

@{
                       Html.Kendo().MultiSelectFor(model => model.ActivityIds)
                           .BindTo(new SelectList(ViewBag.Activity, "ActivityId", "ActivityName"))
                           .Value(new SelectList(ViewBag.SelectedActivites, "ActivityId", "ActivityName"))
                           
                           .Placeholder("Select Activity ..")                         
                           .HtmlAttributes(new { style = "width: 800px;" })
                           .Render();
                   }

ViewBag.Activity = db.GetActivityList(Constants.APP_SC).ToList();
            if(smallCellViewModel.HasValue() && smallCellViewModel.ActivityIds.HasValue())
            {
                ViewBag.SelectedActivites = db.GetActivityList(Constants.APP_SC).Where(c=>smallCellViewModel.ActivityIds.
                    Contains(c.ActivityId)).ToList();
            }

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 19 Mar 2014, 03:06 PM
Hi Mac,

I tried to reproduce the issue locally, but everything worked as expected. Could you please check this screencast and let me know if using this approach works for you? Also, can you confirm that the query returns any items and the SelectedActivites is populated?

Regards,
Alexander Popov
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
MultiSelect
Asked by
Mac P
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or