I am running umbraco version 7 and have created a DropDown list data type called 'productCategories'. I have populated this dropdown list with a number of prevalues and would like to produce a partial view that takes these prevalues and renders them into an unordered list as opposed to a dropdown list. Is this possible?
Thanks for that Mike, I am new to both Umbraco and .Net but after I posted I further researched and found that the PreValues.GetPreValues was the route to go.
However when I used your code the following error appeared:
System.InvalidOperationException: Sequence contains no matching element
When I use the following code (taking out the reference to the name of the Data Type) where 1964 is the nodeID of my Data type I do not get an error:
var prevalues = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(1964);
foreach (var item in prevalues){
<p>@prevalues</p>
}
The output is the correct number of paragraph tags as are prevalues in my data type but they all just say:
System.Collections.SortedList
Do you know the way of calling the prevalues into the paragraph tags?
Enumerating a SortedList is not very intuitive - but you can do it like this:
var prevalues = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(1964).Values;
var enumerator = prevalues.GetEnumerator();
while (enumerator.MoveNext())
{
<p>@((PreValue)enumerator.Current).Value</p>
}
I tried your code Andy but for some reason no paragraph tags were being rendered onto the page (inside the while loop).
However I seem to have got what I wanted with this piece of code, not sure if it is correct but helped me and may help others
Gettings values from a DropDown list data type
I am running umbraco version 7 and have created a DropDown list data type called 'productCategories'. I have populated this dropdown list with a number of prevalues and would like to produce a partial view that takes these prevalues and renders them into an unordered list as opposed to a dropdown list. Is this possible?
SortedList values = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(umbraco.cms.businesslogic.datatype.DataTypeDefinition.GetAll().First(dtDef => dtDef.DataType.DataTypeName.ToString() == "productCategories").DataType.DataTypeDefinitionId);
You might want to watch for front end use though.. as I think this will always hit the database....
Thanks for that Mike, I am new to both Umbraco and .Net but after I posted I further researched and found that the PreValues.GetPreValues was the route to go. However when I used your code the following error appeared:
When I use the following code (taking out the reference to the name of the Data Type) where 1964 is the nodeID of my Data type I do not get an error:
The output is the correct number of paragraph tags as are prevalues in my data type but they all just say:
System.Collections.SortedList
Do you know the way of calling the prevalues into the paragraph tags?
Enumerating a SortedList is not very intuitive - but you can do it like this:
I tried your code Andy but for some reason no paragraph tags were being rendered onto the page (inside the while loop). However I seem to have got what I wanted with this piece of code, not sure if it is correct but helped me and may help others
Basically this example on the Umbraco website: http://our.umbraco.org/wiki/reference/umbracolibrary/getprevalues
is working on a reply...