Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Roger Withnell 128 posts 613 karma points
    May 30, 2015 @ 13:22
    Roger Withnell
    0

    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

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 30, 2015 @ 15:55
    Dennis Aaen
    100

    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

Please Sign in or register to post replies

Write your reply to:

Draft