html helper in OptionLabel

4 posts, 0 answers
  1. Silviya
    Silviya avatar
    5 posts
    Member since:
    Mar 2015

    Posted 16 May 2015 Link to this post

    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

  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 20 May 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Silviya
    Silviya avatar
    5 posts
    Member since:
    Mar 2015

    Posted 20 May 2015 Link to this post

    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.

     

  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 22 May 2015 Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready