简体   繁体   English

Umbraco通过别名查找内容

[英]Umbraco find Content by alias

So far, I am fetching a content by id and works fine. 到目前为止,我正在通过id获取内容,并且工作正常。

 var footerSection = Umbraco.TypedContent(1174);

Although, I am trying to have the same result by querying 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. 我非常确定文档别名为“ footerSection”-即使在第一次(成功)调用中我也具有此信息,但它返回null。

Any reasons that might cause this? 有什么原因可能导致这种情况吗?

Any help is welcome! 欢迎任何帮助!

Your footer node is probably a descendant of root so you probably need to adjust the code a little bit. 页脚节点可能是root的后代,因此您可能需要稍微调整一下代码。

var foundFooterSection = umbracoHelper
    .TypedContentAtRoot()
    .SelectMany(root => root.Descendants())
    .Where(x => x.DocumentTypeAlias == "footerSection")
    .ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM