Copied to clipboard

Flag this post as spam?

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


  • NewGuy 4 posts 34 karma points
    Jun 23, 2014 @ 19:30
    NewGuy
    0

    'Umbraco.Web.Models.DynamicPublishedContentList' does not contain a definition for 'Count'

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    @{

        Layout = "umbLayout.cshtml";

        var siteroot = CurrentPage.AncestorOrSelf(1);

        var children = siteroot.Children.Count();

    <main id="default-wrapper">

    @children

    </main>

    I've stripped out everything in the view, but I am still getting this error. I am just trying to retrieve the number of children. Does anybody know why this his happening?

    Umbraco Newb

    Using Umbraco 7.1.4. 

     

    Thanks!

  • Jeavon Leopold 3042 posts 13382 karma points MVP 8x admin c-trib
    Jun 23, 2014 @ 19:43
    Jeavon Leopold
    0

    Hey and welcome to Our!

    Try this:

    var children = siteroot.Children().Count();
    

    Jeavon

  • NewGuy 4 posts 34 karma points
    Jun 23, 2014 @ 19:55
    NewGuy
    0

    Thanks for the quick reply Jeavon. Unfortunately it is still buggin out.

  • Jeavon Leopold 3042 posts 13382 karma points MVP 8x admin c-trib
    Jun 23, 2014 @ 20:39
    Jeavon Leopold
    0

    Darn, could you try

    DynamicPublishedContent siteroot = CurrentPage.AncestorOrSelf(1)
    
  • NewGuy 4 posts 34 karma points
    Jun 23, 2014 @ 20:50
    NewGuy
    0

    That works! Do you know why my original code didnt work?

  • Jeavon Leopold 3042 posts 13382 karma points MVP 8x admin c-trib
    Jun 23, 2014 @ 20:58
    Jeavon Leopold
    0

    It should of worked, but It's because the Children() method is a extension method which is not being found when siteroot was of type dynamic. I will investigate further to see if it can be fixed in Core.

  • Jeavon Leopold 3042 posts 13382 karma points MVP 8x admin c-trib
    Jun 24, 2014 @ 10:33
    Jeavon Leopold
    0

    Ok, I'm confused, I've been trying to recreate this issue but I just can't.

    This snippet works for me, regardless of what I do:

     @{        
        var siteroot = CurrentPage.AncestorOrSelf(1);
        var children = siteroot.Children().Count();
    
    }
    <p>@children</p>
    

    Could you please try this again just to see if maybe something was cached?

    Thanks,

    Jeavon

  • Simon 692 posts 1068 karma points
    Mar 06, 2015 @ 11:19
    Simon
    0

    Hi Jeavon,

    I have faced an issue, that I don't know exaclty what is happening.

    I have published an umbraco site online. And the same site, I have published also locally, to compare.

    Locally, it works fine, but online, there are some errors related to the same issue that you have been talking about.

    I tried this code snipper in both envrionments:

     @{        
       
    var siteroot =CurrentPage.AncestorOrSelf(1);
       
    var children = siteroot.Children().Count();

    }
    <p>@children</p>

    The site which was published locally, no errors, but the same code online, this error popup.

     

    Similiar errors are occuring online, for example in the breadcrumbs macro, for the Any() method.

    I have checked that every same file published locally is the same online.

    Do you have an idea what might be the problem?

    Thanks in advance

    Kind Regards

  • Damian Chambers 20 posts 84 karma points
    Apr 17, 2015 @ 00:29
    Damian Chambers
    0

    I am getting similar error.

  • Anja Beisel 8 posts 28 karma points
    May 15, 2015 @ 13:54
    Anja Beisel
    0

    Had the same error. Yesterday .Length, .Count(), .Any() was working today it doesn't whatever I try. For the time beeing I have a little workaround:

    foreach( var kid in CurrentPage.Children ) { i++; }

    if( i > 0 ) { ... do something ... }

Please Sign in or register to post replies

Write your reply to:

Draft