I am using Umbraco CMS and facing a problem in accessing the Contact us page using the AncestorOrSelf method.
I have tried to explain it by example.
- Content
-- Home (level = 1)
-- About Us (level = 2)
-- Contact Us (level = 2)
-- News Area (level = 2)
-- News Item 1 (level = 3)
-- News Item 2 (level = 3)
-- Other Node (level = 1)
By using Model.Content.AncestorOrSelf(1) I am getting the Other Node
(level = 1 as in example).
How could I get the contact us page which is under Home level?
AncestorOrSelf(level)will traverse upwards through the ancestors of the node you are querying from. It will stop at the first node it finds that matches the level specified in the parameter.In your case that would mean that doing a
AncestorOrSelfquery from any of the level 2 or level 3 nodes would traverse upwards until it reaches the Home node. It should never reach the Other Node unless you are doing it from a child/descendant node below the Other Node.If this is not the case - what is the current page when you are executing this query?