Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim C 161 posts 528 karma points
    May 25, 2016 @ 08:45
    Tim C
    0

    Dropdown : show text not value in templates / partial views

    If I add a default drop down editor to a document type with prevalues for the option text, when editing the document, Umbraco adds values automatically eg

    <select>
    <option value="1">Option AAA</option>
    <option value="2">Option BBB</option>
    <option value="3">Option CCC</option>
    </select>
    

    which is as expected. When I output this field say in a template,

    @Umbraco.Field("myDropdown").ToString()
    

    it neatly outputs the text eg

    "Option BBB"

    even though what is stored in the database table (cmsPropertyData) is the value

    eg "2".

    However I have created a custom property editor dropdown (for various reasons) and allowed the prevalues to define the value that should be stored as well as the text.

    In the document editor I see the dropdown as it should be eg

    <select>
    <option value="10">Custom dropdown : Option DDD</option>
    <option value="20">Custom dropdown : Option EEE</option>
    <option value="30">Custom dropdown : Option FFF</option>
    </select>
    

    and it correctly stores the value to the database. So far so good.

    But, when I output to a template

    Umbraco.Field("myCustomDropdown")
    

    instead of seeing the text eg

    "Custom dropdown : Option EEE"

    I see the stored value eg "30"

    I am not entirely surprised.

    My question : how does the Umbraco built in dropdown do the conversion from value to text on the fly and can I reproduce this for my custom drop down, otherwise I am going to have to hard code conversions every time I use this control. There must be some code on the built in editor somewhere? Can I pinch sorry refactor this?

    I hope this makes sense.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies