Umbraco Get Current Page in Partial View

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,

@inherits UmbracoTemplatePage
    var currentPage = Umbraco.Content(umbraco.NodeFactory.Node.GetCurrent().Id);

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

@if (currentPage.DocumentTypeAlias == "home")
     // some code

And it works.

comments powered by Disqus

About the author

  • Abhith Rajan

    Abhith Rajan

    Abhith Rajan is a full-stack developer, consultant, Sysberries employee, and biker. Who passionate about C# and JavaScript. Works on his blog, his personal finance web app and its react native mobile app in his free time.

    Buy me a coffeeBuy me a coffee