Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm having a hard time accessing the value of a simple dropdown.
The dropdown has 2 prevalues, defined in the data type:
However, when i try to acces the selected value using this fairly simple code it returns a number (an ID?) and not the selected value.
var theme = content.GetValue<string>("theme");
Example from debugging: (Dark is selected here)
What am I doing wrong?
What is content - how is this passed, are you in a macro / view / partial?
content
With an IPublishedContent object this is working for me:
Model.GetPropertyValue<string>("BlockTextPosition")
Hi Steve :)
content is an IContent, and I'm accessing it in a class which handles events from the ContentService
IContent
ContentService
At the moment I'm subscribing to the ContentService.Saved event.
ContentService.Saved
private void OnContentSaved(IContentService sender, SaveEventArgs<IContent> saveEventArgs)
It seems that IContent does not have the method GetPropertyValue<T>.
GetPropertyValue<T>
However, when going over my code again, I found that I've already encountered this problem some time ago and fixed it then
umbraco.library.GetPreValueAsString(Convert.ToInt32(theme));
Hi,
Yes - that will work!
I think the umbraco.library stuff is deprecated - probably should be using the DataType Service
https://our.umbraco.org/documentation/reference/Management/Services/DataTypeService
But it works, so it's up to you to break it :)
Steve
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Getting the correct value from a dropdown
I'm having a hard time accessing the value of a simple dropdown.
The dropdown has 2 prevalues, defined in the data type:
However, when i try to acces the selected value using this fairly simple code it returns a number (an ID?) and not the selected value.
Example from debugging: (Dark is selected here)
What am I doing wrong?
What is
content
- how is this passed, are you in a macro / view / partial?With an IPublishedContent object this is working for me:
Hi Steve :)
content
is anIContent
, and I'm accessing it in a class which handles events from theContentService
At the moment I'm subscribing to the
ContentService.Saved
event.It seems that
IContent
does not have the methodGetPropertyValue<T>
.However, when going over my code again, I found that I've already encountered this problem some time ago and fixed it then
Hi,
Yes - that will work!
I think the umbraco.library stuff is deprecated - probably should be using the DataType Service
https://our.umbraco.org/documentation/reference/Management/Services/DataTypeService
But it works, so it's up to you to break it :)
Steve
is working on a reply...