Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Henk Jan Pluim 15 posts 67 karma points
    Aug 29, 2014 @ 09:13
    Henk Jan Pluim
    0

    Loop through properties

    Hi,

    I am currently working on an API for AngularJS integration. Via this custom apicontroller i would like to return the umbraco content tree in JSON. Currently this works but i cant seem to loop through to properties of the DynamicPublishedContent item to get the names and values.

    These property are of type IPublishedProperty and i can view them in the quickwatch. But if i try to get this property value it gives an RuntimeBinderException.

    Does anybody knows why this is the case? What can i do to get this properties in an array?

  • Henk Jan Pluim 15 posts 67 karma points
    Aug 29, 2014 @ 10:36
    Henk Jan Pluim
    101

    I managed to get the properties by making a reference to the contentservice. The returned object is of type Content. (Umbraco.Core.Models) Then i can loop through the properties:

        var contentService = Services.ContentService;  
        var contentItem = contentService.GetById(page.Id);
    
        foreach (var prop in contentItem.Properties)
                    {
                       // prop.Alias , prop.Value
                        ...
                    }
    

    Strange that by using dynamic representation with UmbracoHelper you cant loop through this properties:

        var umbracoHelper = new Umbraco.Web.UmbracoHelper(UmbracoContext);
        var contentItem = umbracoHelper.Content(page.Id);
    
        foreach (var prop in contentItem.Properties)
                        {
                           // error
    
                        }
    
Please Sign in or register to post replies

Write your reply to:

Draft