Computer Magic Logo
Parent of a page

Saturday, August 8, 2015

Published by Aristotelis Pitaridis

Sometimes we need to know the parent of the current page. In order to do it we use the Parent property. 

Let’s see how to do it using a typed representation of the page.

@if (Model.Content.Parent != null)
{
    <p>The parent page has the name @Model.Content.Parent.Name</p>
}
else
{
    <p>There are are not child pages.</p>
}

The equivalent code using the dynamic representation of the page is the following.

@if (CurrentPage.Parent != null)
{
    <p>The parent page has the name @CurrentPage.Parent.Name</p>
}
else
{
    <p>There are are not child pages.</p>
}