Copied to clipboard

Flag this post as spam?

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


  • Jacob Polden 67 posts 177 karma points
    Jun 08, 2012 @ 12:42
    Jacob Polden
    0

    Does not contain a definition for Children... MYSTERY!

    I am making a macro designed to list Related Posts. The macro compiles, however failes at run time. It throws this error:

     

    umbracoMacro Error Loading Razor Script (file: Blogpost Related Pages) 'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'    at CallSite.Target(Closure , CallSite , Object )
      at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
      at ASP._Page_macroScripts_RelatedPosts_cshtml.Execute() in d:\home\mblearning.orcare.com\htdocs\macroScripts\RelatedPosts.cshtml:line 8
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
    1.021373536 1.007194
    umbracoMacro Loading IMacroEngine script [done] 1.021497888 0.000124
    umbracoMacro Error loading MacroEngine script (file: RelatedPosts.cshtml, Type: ''
    'umbraco.MacroEngines.DynamicNodeList' does not contain a definition for 'Children'
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)

     

    Surely this must be a dll problem? This is the macro I am using

     

    <h3 class="commentsheader">Related posts</h3>
    <ul class="relatedPostsList">
      @{    
        var currentTags umbraco.cms.businesslogic.Tags.Tag.GetTags(@Model.Id);
        int 0;
        bool found false;
        
        foreach (var blogItem in Model.AncestorsOrSelf("Blog").Children.Where("Visible && i < 5 && NodeTypeAlias == \"BlogPost\"").OrderBy("createDate desc"))
          {  
          
               found false;
               foreach (var relatedTags in umbraco.cms.businesslogic.Tags.Tag.GetTags(@blogItem.Id))
                {
                    if(currentTags.Contains(relatedTags&found == false)
                     {
                       found true;
                       <li>
                          <href="@blogItem.Url">@blogItem.Name</a>
                       </li>
                      }
                 i++;
                 }
           }                
      }
    </ul>

     

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Jun 08, 2012 @ 13:06
    Michael Latouche
    0

    Hi jacob,

    The problem comes from the fact that yout statement Model.AncestorsOrSelf("Blog") returns a DynamicNode List, and not a single DynamicNode. And the DynamicNodeList object does not have the "Children" property, only the DynamicNode does.

    In your case you probably have only one "Blog" node, so what you need to do is extract the "first node" from the list, so something like

    Model.AncestorsOrSelf("Blog").First().Children...

    Hope this helps.

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft