Umbraco Razor Display Links to Next, Previous and Parent page or node

The Following Razor code for Umbraco displays Next and Previous Buttons / Links and a Return to the Parent node Button / Link:

Example 1:


<umbraco:Macro runat="server" language="cshtml">
   @{
        if (@Model.Previous() != null) {
            <a href="@Model.Previous().Url">Previous Image</a>
}

var currentPg = Model;
<a href="@currentPg.Parent.Url">View all @currentPg.Parent.Name</a>

if (@Model.Next() != null) {
            <a href="@Model.Next().Url">Next Image</a>
        }
    }
</umbraco:Macro>



Example 2:

This Example shows you how to ignore pages that are hidden from the navigation in Umbraco.



   @{

if (@Model.Previous() != null) {
var node = Model.Previous();
if (node.Visible)
{
            <a class="button green"  href="@Model.Previous().Url">@Model.Previous().PageTitle Images</a>
}
        }

 
 
  var currentPg = Model;
  if (currentPg.Visible)
{
<a style="margin-left:5px;margin-right:5px;" class="button blue" href="@currentPg.Parent.Url">Portfolio</a>
}




if (@Model.Next() != null)
{
var node = Model.Next();
if (node.Visible)
{
            <a class="button green"  href="@Model.Next().Url">@Model.Next().PageTitle Images</a>
}
}


    }

Comments

Popular posts from this blog

Umbraco Razor Sort Nodes Ascending or Descending

Umbraco Razor get Querystring

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco