In umbraco, is it possible to check if certain property exist for particular node?
For example, I am having 5 nodes and I am having media picker property for first node alone. I need to check all the nodes whether media picker property is available for nodes or not?
The hasOwnProperty() method will check if an object contains a direct property and will return true or false if it exists or not. The hasOwnProperty() method will only return true for direct properties and not inherited properties from the prototype chain.
The hasOwnProperty() method returns true if the specified property is a direct property of the object — even if the value is null or undefined . The method returns false if the property is inherited, or has not been declared at all.
Method 1: Using the typeof operator The typeof operator returns the type of the variable on which it is called as a string. The return string for any object that does not exist is “undefined”. This can be used to check if an object exists or not, as a non-existing object will always return “undefined”.
Every object has general properties including its layer, color, linetype, linetype scale, lineweight, transparency, and plot style.
If you are using Razor you can do it like this:
Model.HasProperty("MyPropertyAlias")
And you can check if the property contains a value as follows:
Model.HasValue("MyPropertyAlias")
I think you can just check property existence by comparing to null:
Node somenode = new Node(myNodeID);
if (somenode.GetProperty("myProperty") != null)
{
string myProperty = somenode.GetProperty("myProperty").Value.ToString();
//Do something with myProperty
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With