Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm building a dynamic menu in a partial macro using MVC and am trying to get the home node with:
@{var homeNode = Model.AncestorOrSelf("Home");}
but this line is giving an error and no information as to what the error is.
What am I doing wrong?
Your help would be much appreciated.
Thanking you in anticipation.
Roger
Hi Roger,
If you are using dynamic Razor then you will ned to do it like this
@{var homeNode = CurrentPage.AncestorOrSelf("Home");}
If you are using strongly typed Razor then you will ned to do it like this
@{var homeNode = Model.Content.AncestorOrSelf("Home");}
Here are some cheatsheets that shows the different methods in Razor https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets I know it says for Umbraco 6, but you can also use it in version 7
Hope this helps,
/Dennis
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Model.AncestorOrSelf giving an error in partial macro
I'm building a dynamic menu in a partial macro using MVC and am trying to get the home node with:
@{var homeNode = Model.AncestorOrSelf("Home");}
but this line is giving an error and no information as to what the error is.
What am I doing wrong?
Your help would be much appreciated.
Thanking you in anticipation.
Roger
Hi Roger,
If you are using dynamic Razor then you will ned to do it like this
If you are using strongly typed Razor then you will ned to do it like this
Here are some cheatsheets that shows the different methods in Razor https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets I know it says for Umbraco 6, but you can also use it in version 7
Hope this helps,
/Dennis
is working on a reply...