首页 > 解决方案 > Kentico IEnumerable在我的控制器中为空

问题描述

我正在使用标准方法来获取页面的属性:

ClientLogosDatasource datasourceItem = ClientLogosDatasourceProvider.GetClientLogosDatasource(datasourceNodeGuid, "en-us", SiteContext.CurrentSiteName)
.Columns("ClientLogosDatasourceHeadingText", "ClientLogosDatasourceImages");

其中有一个“附件”表单组件

1

但是当我尝试枚举我的 MVC 应用程序中的属性时,枚举是空的。

1

单步执行代码,它基本上完全跳过了 foreach。我不确定为什么 Images 属性为空/空。

任何帮助,将不胜感激!

标签: kenticokentico-12kentico-mvckentico-api

解决方案


这是基本的API 示例(不是特定于 MVC 的),但应该让您朝着正确的方向前进。

// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

// Gets a page
TreeNode page = tree.SelectNodes()
    .Path("/Articles")
    .OnCurrentSite()
    .Culture("en-us")
    .TopN(1)
    .FirstOrDefault();

if (page != null)
{
    // Iterates over all attachments of the page
    foreach (DocumentAttachment attachment in page.AllAttachments)
    {
        // Perform any action with the attachment object (DocumentAttachment)
    }
}

// To get only unsorted attachments, use the TreeNode.Attachments collection
// To get only page field attachments, use the TreeNode.GroupedAttachments collection

推荐阅读