I am using Umbraco cloud and have created a drop down menu to select the state (NSW, VIC etc) in the members section and I am using a partial view.
When the state is selected it displays a value and not the text (NSW)
@foreach (var member in ApplicationContext.Current.Services.MemberService.GetMembersByMemberType("activeMembers"))
{
var prac1st = member.GetValue<string>("practice1State");
<p> @prac1st </p>}
If the dropdown list is made from prevalues as shown in the screenshot below you'll need to do some extra lookups in the code.
var memberStateDataType = Umbraco.DataTypeService.GetDataTypeDefinitionByName("Member State - Dropdown list");
var memberStateDictionary = Umbraco.DataTypeService.GetPreValuesCollectionByDataTypeId(memberStateDataType.Id).PreValuesAsDictionary;
foreach (var member in ApplicationContext.Current.Services.MemberService.GetMembersByMemberType("activeMembers"))
{
var stateProperty = member.Properties.FirstOrDefault(p => p.PropertyType.Alias == "practice1State");
var selectedPreValueId = int.Parse((string)stateProperty.Value);
var selectedPreValue = memberStateDictionary.FirstOrDefault(preValue => preValue.Value.Id == selectedPreValueId);
// next line is the state e.g. "NSW"
var selectedState = selectedPreValue.Value.Value;
}
It's not very elegant but if you're doing it in Razor I think this is what you have to do. If anyone else can provide something better I'd love to know.
Im dealing with the issue to render SELECTED VALUE to html .
@if (Model.HasValue("productcategory"))
{
var memberStateDataType = Umbraco.DataTypeService.GetDataTypeDefinitionByName("productcategory- Dropdown");
var memberStateDictionary = Umbraco.DataTypeService.GetPreValuesCollectionByDataTypeId(memberStateDataType.Id).PreValuesAsDictionary;
foreach (var member in ApplicationContext.Current.Services.MemberService.GetMembersByMemberType("activeMembers"))
{
var stateProperty = member.Properties.FirstOrDefault(p => p.PropertyType.Alias == "practice1State");
var selectedPreValueId = int.Parse((string)stateProperty.Value);
var selectedPreValue = memberStateDictionary.FirstOrDefault(preValue => preValue.Value.Id == selectedPreValueId);
// next line is the state e.g. "NSW"
var selectedState = selectedPreValue.Value.Value;
<p>@selectedState</p>
}
}
Drop down menu returning number not string
I am using Umbraco cloud and have created a drop down menu to select the state (NSW, VIC etc) in the members section and I am using a partial view.
When the state is selected it displays a value and not the text (NSW)
How do I display the value NSW, VIC etc
If the dropdown list is made from prevalues as shown in the screenshot below you'll need to do some extra lookups in the code.
It's not very elegant but if you're doing it in Razor I think this is what you have to do. If anyone else can provide something better I'd love to know.
Hello Jf
Im dealing with the issue to render SELECTED VALUE to html .
Do you have a way how to render it simply ?
Thank you.
Thanks jf
is working on a reply...