'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?
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.
'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!
Hey and welcome to Our!
Try this:
Jeavon
Thanks for the quick reply Jeavon. Unfortunately it is still buggin out.
Darn, could you try
That works! Do you know why my original code didnt work?
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.
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:
Could you please try this again just to see if maybe something was cached?
Thanks,
Jeavon
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:
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
I am getting similar error.
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 ... }
is working on a reply...