This sounds simple but i can't work it out, i just want to write to screen the page id of the parent of the current page. lets say i have this structure..
Home About (page id 100) ChildPage
If im on ChildPage, how do i get the ID of the about page? i know to get the current page id i can use 'Umbraco.Field("pageID")' but trying Umbraco.Field("ParentId") does not write out the parent id (it actually writes out nothing)
Super - glad that I could help you. I think that you should mark the question as solve so other that comes accross this post can go directly to the solution. You do this by click on the green tick on the left side close to theavatarimageoftheitem whichgaveyou the solutiontoyour question.
Once a again glad that I could help you, and happy Umbraco coding.
Just a quick question, the way im using this means this code also ends up on the home page via a partial view, as the home page has no parent i get an error '
Cannot perform runtime binding on a null reference'
get the page id of the parent?
Hi guys,
This sounds simple but i can't work it out, i just want to write to screen the page id of the parent of the current page. lets say i have this structure..
Home
About (page id 100)
ChildPage
If im on ChildPage, how do i get the ID of the about page? i know to get the current page id i can use 'Umbraco.Field("pageID")' but trying Umbraco.Field("ParentId") does not write out the parent id (it actually writes out nothing)
Hi EsqJ,
The Umbraco.Field refers to the current page, if you see docuementation for Umbraco.Field here https://our.umbraco.org/documentation/Reference/Mvc/views#RenderingafieldwithUmbracoHelper - it says, This is probably the most used method which simply renders the contents of a field for the current content item.
To get the parent page id, you can do it in razor like this:
Hope this helps,
/Dennis
Excellent, just what i needed, Thanks!
Hi EsqJ,
Super - glad that I could help you. I think that you should mark the question as solve so other that comes accross this post can go directly to the solution. You do this by click on the green tick on the left side close to the avatar image of the item which gave you the solution to your question.
Once a again glad that I could help you, and happy Umbraco coding.
/Dennis
Just a quick question, the way im using this means this code also ends up on the home page via a partial view, as the home page has no parent i get an error '
Cannot perform runtime binding on a null reference'
is there a way around this?
Hi EsqJ,
Try this:
Hope this helps,
/Dennis
Hi Dennis,
That worked but i have come across an issue of my own making.
If i have this structure...
Home
About (page id 100)
ChildPage
ChildOfChild
The parent of childofchild is going to be child page, but i still want to get the id of the *root* parent (about us). Does that make sense?
Hi EsqJ,
Then you could do something like this:
You can read about Umbraco.Content here: https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/#Content%28intid%29 if you are using strongly typed razor the snippet looks like this:
You could also create a variable like this:
Hope this helps,
/Dennis
Hi EsqJ,
And if your about page has it´s own document type then you can do it like this also.
Remember to change the Document Type Alias so it match your about page document type alias.
Hope this helps,
/Dennis
is working on a reply...