umbraco | cms

Umbraco Get Current Page in Partial View

This article describes how to get the CurrentPage of Umbraco in a partial view.

Abhith Rajan
Abhith RajanAugust 18, 2017 · 1 min read · Last Updated:

In my website, the header section is a partial view which basically contains the header menus. The menus initially were same for all the pages across my site but I thought to hide some menu in case the current page is not the homepage.

To do that, I needed to get the current page and check whether the current page is the homepage or not, in the header partial.

To get the current page in partial view,

1@inherits UmbracoTemplatePage
2
3@{
4 var currentPage = Umbraco.Content(umbraco.NodeFactory.Node.GetCurrent().Id);
5}

And to check whether it is home page or not, I decided to compare against DocumentTypeAlias as shown below,

1@if (currentPage.DocumentTypeAlias == "home")
2{
3 // some code

And it works.

Abhith Rajan

Written byAbhith Rajan
Abhith Rajan is a software engineer by day and a full-stack developer by night. He's coding for almost a decade now. He codes 🧑‍💻, write ✍️, learn 📖 and advocate 👍.
Connect

Is this page helpful?

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Related ArticlesView All