Hey guys, I don't know if it's just late here or what but I just can't for the life of me see what's going wrong here. I've got a LINQ statement that I'm trying to execute, but a certain custom property ("client")'s value of the nodes are always returning null. I expect JSON object or better yet serialize to my strongly typed model. To debug I extracted a method, as below:
As you can see I can now examine in more detail where the problem is... the GetPropertyValue
What might I be missing here? Why can I see it in locals but the function returns null. I have used the function in views with similar custom properties without issue.
Have you got a Property Value Converter that will convert from a JSON string to a JObject? Because Umbraco won't magically do the conversion for you. So if you try and get a strongly-typed model back from an instance of IPublishedContent for a type that hasn't got a converter you will get NULL back.
I'd guess you might need to get the value back as a string and then manually convert it to a JObject.
No I don't... the documentation for GetPropertyDataValue() didn't mention that. It says that at the minimum JObject conversion would definitely be supported for JSON string values, so I just assumed that conversion would work.
I don't understand all that stuff in the link you sent. It seems too complex for what I want to do, which is just get the client.id so I used Newtonsoft.Json to deserialize the
private int GetClientId(Umbraco.Core.Models.IPublishedContent node)
{
var prop = node.GetPropertyValue<string>("client");
if (prop == null) return -1;
var jsonProp = JsonConvert.DeserializeObject<JObject>(prop);
return jsonProp["id"].Value<int>();
}
Node GetPropertyValue returning null
Hey guys, I don't know if it's just late here or what but I just can't for the life of me see what's going wrong here. I've got a LINQ statement that I'm trying to execute, but a certain custom property ("client")'s value of the nodes are always returning null. I expect JSON object or better yet serialize to my strongly typed model. To debug I extracted a method, as below:
As you can see I can now examine in more detail where the problem is... the GetPropertyValue
What might I be missing here? Why can I see it in locals but the function returns null. I have used the function in views with similar custom properties without issue.
Have you got a Property Value Converter that will convert from a JSON string to a JObject? Because Umbraco won't magically do the conversion for you. So if you try and get a strongly-typed model back from an instance of IPublishedContent for a type that hasn't got a converter you will get NULL back.
I'd guess you might need to get the value back as a string and then manually convert it to a JObject.
No I don't... the documentation for GetPropertyDataValue() didn't mention that. It says that at the minimum JObject conversion would definitely be supported for JSON string values, so I just assumed that conversion would work.
I don't understand all that stuff in the link you sent. It seems too complex for what I want to do, which is just get the client.id so I used Newtonsoft.Json to deserialize the
is working on a reply...