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

MultiSelect Datasource SelectList with Selected Property

3 Answers 225 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 24 Mar 2016, 05:10 PM

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)

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 28 Mar 2016, 07:56 AM
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
0
Scott
Top achievements
Rank 1
answered on 28 Mar 2016, 05:54 PM

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)

0
Accepted
Ivan Danchev
Telerik team
answered on 29 Mar 2016, 01:31 PM
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
Tags
MultiSelect
Asked by
Scott
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Scott
Top achievements
Rank 1
Share this question
or