Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 12, 2011 @ 18:00
    Sebastiaan Janssen
    0

    AncestorOrSelf stops working when casting Model to DynamicNode

    I want to have some  intellisense by casting my Model to DynamicNode, but once I do that I get errors. This works:

    <nav> 
        <ul> 
            @foreach (var item in Model.AncestorOrSelf(1).Children.Where("umbracoNaviHide == false"))
            {  
                <li>
                    <a href="@item.Url" @(item.Id == Model.Id ? "class=current" : "")>
                        @item.Name
                    </a>
                </li> 
            }
        </ul> 
    </nav> 
    
    But when I try this one:
    @using umbraco.MacroEngines;
    @{ var currentPage = (DynamicNode)Model; }
    <nav> 
        <ul> 
            @foreach (var item in currentPage.AncestorOrSelf(1).Children.Where("umbracoNaviHide == false"))
    { <li> <a href="@item.Url" @(item.Id == Model.Id ? "class=current" : "")> @item.Name </a> </li> } </ul> </nav>

    I get an error:

    'umbraco.MacroEngines.DynamicNode' does not contain a definition for 'Children' and no extension method 'Children' accepting a first argument of type 'umbraco.MacroEngines.DynamicNode' 

  • Daniel Bardi 927 posts 2562 karma points
    Mar 12, 2011 @ 22:57
    Daniel Bardi
    0

    Could you remove .Children all together?

  • Gareth Evans 143 posts 335 karma points c-trib
    Mar 13, 2011 @ 03:50
    Gareth Evans
    0

    Use this :

    @{ dynamic currentPage = (DynamicNode)Model; }

    Instead of

    @{ var currentPage = (DynamicNode)Model; }

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 13, 2011 @ 11:44
    Sebastiaan Janssen
    0

    Hmm, interesting, so if I define it as a dynamic instead of a var, I loose Intellisense. But it does work just fine indeed!

  • Gareth Evans 143 posts 335 karma points c-trib
    Mar 13, 2011 @ 23:46
    Gareth Evans
    0

    Can you try it without the cast?

    @{ dynamic currentPage = Model; }

     

  • Robin Winslow Morris 20 posts 82 karma points
    Nov 07, 2012 @ 11:41
    Robin Winslow Morris
    0

    Why is this?

Please Sign in or register to post replies

Write your reply to:

Draft