kenticokentico-12kentico-mvckentico-api

Kentico IEnumerable<DocumentAttachment> is empty in my controller


I am using the standard method to get the properties of my page:

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

Which has an 'Attachments' form component

1

But when I attempt to enumerate over the property in my MVC application, the enumeration is empty.

1

Stepping through the code, it basically skips the foreach completely. I'm not sure why the Images property is null/empty.

Any help would be appreciated!


Solution

  • Here's the basic API example (not MVC specific) but should get you in the right direction.

    // 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