Cannot set initial values from viewmodel

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

    Posted 17 Mar 2014 Link to this post

    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();
                }
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 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?

    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.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top