Reputation: 2384
I have added a few prevalues to a dropdown-list. When Im trying to get the value of a property that uses my dropdownlist-data-type I keep getting the "key" of the preValue as the value of the property.. but thats not what Im after.. I need and want to get the actuallt prevalue-string that I entered as my prevalue..
Any ideas?
Oh and btw.. I need to do it using C#..
EDIT
This is what I have tried so far.. and it sort of works.. but It retrives a list of lists that I cant do any quering against..
PreValues.GetPreValues(new Document(statistic.ParentId,true).getProperty("identifier").PropertyType.DataTypeDefinition.DataType.DataTypeDefinitionId).Values
Upvotes: 4
Views: 8844
Reputation: 2915
I didn't need it for drop down list. From Umbraco documentation:
@if (Model.Content.HasValue("superHero"))
{
<p>@Model.Content.GetPropertyValue("superHero")</p>
}
@if (CurrentPage.HasValue("superHero"))
{
<p>@CurrentPage.superHero</p>
}
However, for radiolist, the prevalue can be accessed as follows:
@if (Model.Content.HasValue("miniFigure"))
{
var preValue = Umbraco.GetPreValueAsString(Model.Content.GetPropertyValue<int>("miniFigure"));
<p>@preValue</p>
}
@if (CurrentPage.HasValue("miniFigure"))
{
var preValue = Umbraco.GetPreValueAsString(CurrentPage.miniFigure);
<p>@preValue</p>
}
Upvotes: 1
Reputation: 25
Using Umbraco version 7.53, I just did this, to get the dropdown value:
string dropdownTextValue = slider.GetProperty("dropdownAlias").DataValue.ToString();
Upvotes: 0
Reputation: 6083
I am using below approch to get dropdown list value as text and id
// Node ID of content node in which dropdown has been used
int NodeIdOfContent = 1111;
Document docMfsFeedSettings = new Document(NodeIdOfContent);
int preValueID = docMfsFeedSettings.getProperty("dropDownAliasName").Value)
// Retrieve Text value
string textValue = umbraco.library.GetPreValueAsString(
Convert.ToInt32(docMfsFeedSettings.getProperty("dropDownAliasName").Value));
Upvotes: 5
Reputation: 10922
It's kind of a mess, but using the PreValues object here's what you would do to get an IEnumerable of just the values:
...
int id = statistic.ParentId;
var node = new Document(id, true);
var property = node.getProperty("dropdown");
var dataTypeDefinitionId = property.PropertyType.DataTypeDefinition.DataType.DataTypeDefinitionId;
// Cast the SortedList to an IEnumerable of DictionaryEntry and then
// select the PreValue objects from it:
var preValues = PreValues.GetPreValues(dataTypeDefinitionId)
.Cast<DictionaryEntry>()
.Select(d => d.Value as PreValue);
// Select just the values from the PreValue objects:
var values = preValues.Select(p => p.Value);
Another approach would be to use the umbraco.library.GetPrevalues(int id)
method. However both approaches are messy in their own ways.
Upvotes: 2