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
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
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?
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
which is as expected. When I output this field say in a template,
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
and it correctly stores the value to the database. So far so good.
But, when I output to a template
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.
is working on a reply...