how to get Umbraco dropdown list datatype values on cshtml page?
Hi
I am using Umbraco 7.2.0.
I have the requirement to add Dropdown list datatype on Umbraco Content page with values and then need to check / compare the values / text of that dropdown on front website (cshtml) pages and need to do some operations.
Right now i am able to add the value to the dropdown list but don't know how to get the Selected Value / Text on cshtml page ?
And also you can use DataTypeService to get values.
@{
Umbraco.Core.Services.DataTypeService serviceData = new Umbraco.Core.Services.DataTypeService();
var prevalues = serviceData .GetPreValuesByDataTypeId(1245); // 1245 = Data type Id
}
Then you can get drop down list selected value using javascript.
how to get Umbraco dropdown list datatype values on cshtml page?
Hi
I am using Umbraco 7.2.0.
I have the requirement to add Dropdown list datatype on Umbraco Content page with values and then need to check / compare the values / text of that dropdown on front website (cshtml) pages and need to do some operations.
Right now i am able to add the value to the dropdown list but don't know how to get the Selected Value / Text on cshtml page ?
Can anyone please help me here ?
thanks
rohan dave
Hi Rohan,
You can get data type Dropdown list value in Razor using below code.
you can perform whatever operation you want using above varible.
Or else you can refer below link.
https://our.umbraco.org/wiki/reference/umbracolibrary/getprevalues
Hope this will help you.
Regards,
Urvish Mandaliya
And also you can use DataTypeService to get values.
Then you can get drop down list selected value using javascript.
Hi Rohan,
You can get the selected value from the current page you can use this Razor if you are using Dynamic Razor.
If you are using strong typed then I has to look this this.
You can find the documentation about how to work with the dropdown list here: https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/DropDown-List
Hope this helps,
/Dennis
is working on a reply...