I am using the Drodown Dictionary component created by Matt Brailsford and Lee Kelleher (https://github.com/leekelleher/umbraco-dictionary-dropdown)
I have it installed and it is working great, however I am struggling trying to work out how to look through the values of the data type via code. For the normal Umbraco dropdown I had this code:
Obviously the GetPreValues method does not return the items, so what method should be used? If I look in the cmsPropertyType table the value column is set as follows:
Managed to sort it, for future rference the best way of doing this is using the JSON.Net Deserialize method and create a list of a custom class matching the values above, e.g.
Drodpown Dictionary Component Values
I am using the Drodown Dictionary component created by Matt Brailsford and Lee Kelleher (https://github.com/leekelleher/umbraco-dictionary-dropdown)
I have it installed and it is working great, however I am struggling trying to work out how to look through the values of the data type via code. For the normal Umbraco dropdown I had this code:
Obviously the GetPreValues method does not return the items, so what method should be used? If I look in the cmsPropertyType table the value column is set as follows:
[ { "key": "Mr", "value": "Mr" }, { "key": "Mrs", "value": "Mrs" }, { "key": "Miss", "value": "Miss" }, { "key": "Ms", "value": "Ms" }, { "key": "Dr", "value": "Dr" }, { "key": "Prof", "value": "Prof" } ]
This does appear to exist within the TypedValue field when the GetPreValues method is called?
Managed to sort it, for future rference the best way of doing this is using the JSON.Net Deserialize method and create a list of a custom class matching the values above, e.g.
public List<SelectListItem> GetTitleTypes()
{
Umbraco.Core.Models.PreValueCollection collection = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(1333);
PreValue preval = collection.PreValuesAsDictionary.Values.FirstOrDefault();
List<keyvalue> values = JsonConvert.DeserializeObject<List<keyvalue>>(preval.Value);
List<SelectListItem> items = new List<SelectListItem>();
foreach(keyvalue val in values)
{
SelectListItem item = new SelectListItem();
item.Text = val.key;
item.Value = val.value;
items.Add(item);
}
return items;
}
class keyvalue
{
public string key { get; set; }
public string value { get; set; }
}
is working on a reply...