Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 936
sidy3d Avatar asked Dec 11 '22 03:12

sidy3d


1 Answers

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>
}
like image 89
wingyip Avatar answered Jan 18 '23 14:01

wingyip