Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm trying to get all descendants of the rootnode (or any node for that matter) from my UmbracoApiController, filtered with Linq.
So basicly what I would want to do is:
rootnode.Descendants(a => a.DocumentTypeAlias == "myDocType" && a.Name == "myName")
This is documented at: https://our.umbraco.org/Documentation/Implementation/Routing/MVC/querying
But somehow, when I select the rootnode form the UmbracoApiController, my IPublishedContent object doesn't have a Descendants() method.
var root = Umbraco.TypedContentAtRoot().First();
It does have a Children property, but obviously this only returns all the direct children, and not all descendants.
How else am I able to select all documents, filtered by DocumentTypeAlias, and probably also by other properties (CreatedAt for example)?
it should have decendants ...
root.Descendants().Where(x => x.DocumentTypeAlias == "someDocType");
things to check.
Visual studio 2015 - doesn't do intellisense properly for Umbraco (pre v7.3) - it's an MVC4 / 5 thing, but that might be why you can't see it?
Inheritance - my views are using
if you're inheriting from a model again Intellisense (and the site) might not work.
however, if you want to do things sitewide, i would say have a look at examine, getting nodes of type across a whole site can take some time, using examine is slightly more complex but way faster.
failing that cache the macro or partial view because that will make it quick too.
I do using Visual Studio 2015, but it's not compiling, so IDE should'nt matter.
I managed to fix this however by using the UmbracoHelper
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var blogs = umbracoHelper.TypedContentAtRoot().First().Descendants("Blog").ToList();
I ran into the same issue, turns out I was missing a using statement. I had
But also needed to have
Then the descendants option showed up.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted