@{
var dataTypeId = umbraco.cms.businesslogic.datatype.DataTypeDefinition.GetAll().First(d => d.Text == "Dropdown").Id;
var preValues = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(dataTypeId).Values;
var enumerator = preValues.GetEnumerator();
while (enumerator.MoveNext())
{
var preValueText = ((umbraco.cms.businesslogic.datatype.PreValue)enumerator.Current).Value;
<option>@preValueText</option>
}
Drop down values in razor
Hi
I have a dropdownlist with pre values in CMS. I want to get all items on a razor page.
Thanks
Do yuo want to populate the drop down or or are you just trying to display a dropdownyou have set up in the back office??
Ravi thanks for your attention on problem
I just wanted to show all values which is in CMS for drop down. I wanted to render all on my razor page.
Manish
Hi Manish,
You can do that in razor using this code:
@{ var dataTypeId = umbraco.cms.businesslogic.datatype.DataTypeDefinition.GetAll().First(d => d.Text == "Dropdown").Id; var preValues = umbraco.cms.businesslogic.datatype.PreValues.GetPreValues(dataTypeId).Values; var enumerator = preValues.GetEnumerator();
}
Thank you. Let me try with above one.
Thanks dharmesh it is working except one thing it is showing "Pre values is obsolate" as warning.
Hi Manish,
I am preuming you are working in version 7.x so you may want to take the following approach to get those values
This question and and answer should help you get what you want https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/78280-get-pre-values-for-data-type
Ravi
Yes I am using umbraco 7.x
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.