Why can't I use getPropertyValue on a Content Picker?
I have a content picker on my page which has a value and I have the content picker returning the values I want within my code but when I try and getPropertyValue Name, I get null returned and for some reason the actual LabelTitle throws as a null reference exception even though it does have a value.
It's so close to working and I don't understand why it's not.
The name of the node isn't the same as a property that you would add to a document type.
You can always access the name of the item via the Name property:
eg
var label = typedContent.Name;
if you had another property defined on the picked item you could use
var andAnotherThing = typedContent.GetPropertyValue<string>("andAnotherThing");
(that's if I've understood your question correctly!)
The thing to be wary of here is, if you are handling all this in an event - then is the item, you have picked guaranteed to be in the Umbraco Published Cache at this stage?
Also, how is the LabelTitle added as a property? as an extension to IPublishedContent / Modelsbuilder?
Why can't I use getPropertyValue on a Content Picker?
I have a content picker on my page which has a value and I have the content picker returning the values I want within my code but when I try and
getPropertyValue
Name, I get null returned and for some reason the actualLabelTitle
throws as a null reference exception even though it does have a value.It's so close to working and I don't understand why it's not.
Any help would be great.
Hi Owain
The name of the node isn't the same as a property that you would add to a document type.
You can always access the name of the item via the Name property:
eg
if you had another property defined on the picked item you could use
(that's if I've understood your question correctly!)
The thing to be wary of here is, if you are handling all this in an event - then is the item, you have picked guaranteed to be in the Umbraco Published Cache at this stage?
Also, how is the LabelTitle added as a property? as an extension to IPublishedContent / Modelsbuilder?
regards
Marc
Hi Marc, Thanks for the help.
So this code is run when a reindex takes place in Examine. The good news is that typedContent.Name worked perfectly for me which is great :)
The LabelTitle is just a textstring on the genericPageLabel doctype and is added via ModelsBuilder.
O.
is working on a reply...