George George George George - 2 years ago 169
C# Question

Umbraco find Content by alias

So far, I am fetching a content by id and works fine.

var footerSection = Umbraco.TypedContent(1174);

Although, I am trying to have the same result by quering via document alias and it is not working:

var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var foundFooterSection = umbracoHelper.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "footerSection");

I am pretty sure that document alias is "footerSection" - I have this information even from the first (successful) call but it returns null.

Any reasons that might cause this?

Any help is welcome!

Answer Source

Your footer node is probably a descendant of root so you probably need to adjust the code a little bit.

var foundFooterSection = umbracoHelper
    .SelectMany(root => root.Descendants())
    .Where(x => x.DocumentTypeAlias == "footerSection")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download