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
    Nov 18, 2015 @ 16:53
    Roger Withnell
    1

    Get node from Id in a controller

    I'm passing a node ID from a macro with:

      @Html.Action("Index", "laidSpecialOffersSurface", new { vHomeNodeId });
    

    In the controller, I create the node and then try to access its grandchild with:

    public ActionResult Index(int vHomeNodeId)
    {
        var vHomeNode = new Node(vHomeNodeId);
    
        foreach (var vLevel3 in vHomeNode.Children)
        {
            foreach (var vLevel4 in vLevel3.Children)
    

    But intellisense gives an error with vLevel3.Children saying "object does not contain a definition for Children....".

    What am I doing wrong.

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Mark Bowser 273 posts 860 karma points c-trib
    Nov 18, 2015 @ 17:21
    Mark Bowser
    0

    Although this probably won't solve your problem, one thing to keep in mind is that Node is obsolete. If you are using umbraco 6+, you probably want to do something like Umbraco.TypedContent(vHomeNodeId); You will get back an IPublishedContent object. That's the way to go.

  • Tim Miller 32 posts 252 karma points
    Nov 18, 2015 @ 17:50
    Tim Miller
    0

    I think what you really have going on here is a typing issue. Basically by using var for the variable type in each of your foreach statements the system can't really figure out what it's working with. You can try just changing the vars to Node and be a little more explicit with your typing.

    I think you should probably follow Mark's suggestion and switch to TypedContent.

  • Roger Withnell 128 posts 613 karma points
    Nov 23, 2015 @ 12:46
    Roger Withnell
    0

    Thanks for your replies.

    I fixed the problem by using:

    var vHomeNode = new DynamicNode(vHomeNodeId);
    

    Roger

Please Sign in or register to post replies

Write your reply to:

Draft