MultiSelect Datasource SelectList with Selected Property

4 posts, 2 answers
  1. Scott
    Scott avatar
    4 posts
    Member since:
    Oct 2013

    Posted 24 Mar 2016 Link to this post

    I have a MultiSelectFor using ajax read where I return a list of SelectList Items. Some of the SelectList items have their selected property set to true. The MultiSelect does not display those items as being pre-selected.

    I have attached a file showing the View and the Controller code. (in VB)

  2. Answer
    Ivan Danchev
    Admin
    Ivan Danchev avatar
    1253 posts

    Posted 28 Mar 2016 Link to this post

    Hello Scott,

    The MultiSelect would not pre-select items based on the items' Selected property. In order to pre-select them you can call the widget's Value method with a list of items as shown in the following documentation section.

    Regards,
    Ivan Danchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Scott
    Scott avatar
    4 posts
    Member since:
    Oct 2013

    Posted 28 Mar 2016 in reply to Ivan Danchev Link to this post

    I guess I wasn't exactly clear in my request. All examples that I see show that the starting values are known values. Since I am using the Read method to get the data for the multi-select, is there a way to have the value method receive a list of values from the model or the Read method?

    IE. .value(model.selectedItems) or .value(GetSelectedItems)

  4. Answer
    Ivan Danchev
    Admin
    Ivan Danchev avatar
    1253 posts

    Posted 29 Mar 2016 Link to this post

    Hello Scott,

    Yes, you can call the Value method passing to it ViewBag data or data coming from a method in the controller. As an example please review the sample project attached to Daniel's post in the following thread. The MultiSelect is added in the Edit view. You can create a method similar to the GetCountries one, returning List<string> and pass it to the MultiSelect's Value method:
    .Value(DemoHelper.GetSelectedCountries())

    Another option could be to pass a strings array saved in the ViewBag:
    .Value((string[])ViewBag.Preselected)


    Regards,
    Ivan Danchev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top