Search code examples
umbracoumbraco7custom-data-type

Umbraco get PreValues in a data type


I am using Umbraco 7 and I have created a data type that uses the property type dropdown list publishing keys. How can I get the id of each prevalue?

Thanks in advance.


Solution

  • Something ike this.

    You need to reference:

    @using umbraco.cms.businesslogic.datatype
    

    Then get the Datatype Id from :

    var dataTypeId = umbraco.cms.businesslogic.datatype.DataTypeDefinition
                    .GetAll().First(d=> d.Text == "DataTypeName").Id;
    
    var preValues = PreValues.GetPreValues(dataTypeId).Values;
    var enumerator = preValues.GetEnumerator();
    while (enumerator.MoveNext())
    {
        var preValueText = ((PreValue)enumerator.Current).Value;
        <option>@preValueText</option>
    }