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

html helper in OptionLabel

3 Answers 69 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Silviya
Top achievements
Rank 1
Silviya asked on 16 May 2015, 09:12 AM

Hello,

 

What I am trying to achieve is add a placeholder in a dropdownlist that will display the binded model's property. When trying to use DisplayTextFor in the OptionLabel, I get "undefined" first option in the DropDownList. Is there a way to achieve this? I don't want to hardcode the OptionLabel.

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 20 May 2015, 06:50 AM
Hello Silviya,

I am afraid that it is not clear what exactly your are trying to accomplish. Would it be possible to share code or a runnable demo that demonstrates the issue? This will shed more light on the issue and will help us to understand the case.

Regards,
Georgi Krustev
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
Silviya
Top achievements
Rank 1
answered on 20 May 2015, 07:04 AM

Oh sure,

OptionLabel currently takes either a string or an object, correct?

I am building my form with placeholders because I don't want any labels. Now when it comes to dropdowns, I have decided that the OptionLabel will serve the purpose of a placeholder. For example .OptionLabel("---Department---");

But I also want to pull this string information from my metadata, just the way i do it with LabelFor.

 

So what I am basically trying to achieve is this:

 

.OptionLabel(@Html.DisplayTextFor(c=>c.Title));

 

This however returns undefined as an option label.

 

0
Georgi Krustev
Telerik team
answered on 22 May 2015, 06:58 AM
Hello Silviya,

Well, in that case the @Html.DisplayTextFor(c=>c.Title) method produce an unexpected output. Could you verify that the given method actually generates the correct string? If it does, then I will ask you to send us a repro demo that we can further investigate. It will help us to understand the implementation and find a proper solution of the issue.

Regards,
Georgi Krustev
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
DropDownList
Asked by
Silviya
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Silviya
Top achievements
Rank 1
Share this question
or