Cannot set initial values from viewmodel

2 posts, 0 answers
  1. Mac P
    Mac P avatar
    86 posts
    Member since:
    Mar 2010

    Posted 17 Mar 2014 Link to this post


    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;" })

    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.
  2. Alexander Popov
    Alexander Popov avatar
    1436 posts

    Posted 19 Mar 2014 Link to this post

    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?

    Alexander Popov

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

Back to Top