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

Option Label with BindTo a list of objects

1 Answer 173 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Dan asked on 11 May 2018, 12:56 PM

I want to use the telerik DropDownList to display a list of objects. I saw that the DropDownList support also an optional label but it seems it does not work.

Here is the code

@model IEnumerable<ActionViewModel>
 
@(Html.Kendo().DropDownList()
          .Name("actionDropDownList")
          .DataTextField("Display")
          .DataValueField("Id")
          .BindTo(Model)
          .OptionLabel(Localizer.GetString("Select an action..."))
          .Deferred()
 )

The generated script contains ""optionLabel":{"Name":"Select an action...","Value":"Select an action...","ResourceNotFound":true,"SearchedLocation":null}"

What do I have to give to the OptionalLabel so that it generates the optionalLabel with the properties of DataValueField and DataTextField?

 

 

1 Answer, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 14 May 2018, 07:44 AM
Sorry about this, but it seems that the Localizer.GetString does not return a string, but a LocalizerString that contain the above properties. After changing it to use a string the OptionalLabel worked as expected.
Tags
DropDownList
Asked by
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dan
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or