Copied to clipboard

Flag this post as spam?

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


  • Ras 66 posts 330 karma points
    Jun 08, 2021 @ 07:47
    Ras
    0

    Extracting nested content value from surface controller

    Hello, I'm trying to access some data from a SurfaceController, but I'm having some issues. This is how it looks right now:

    public class PublicationsController : SurfaceController
    {
        [HttpPost]
        public ActionResult GetAll()
        {
            var page = Umbraco.Content(Guid.Parse(/*guid*/));
        }
    }
    

    Not sure if that's a good start, but I can access the properties to some extent. I have a nested content property that holds what I need to access. I can manage to get the alias of this nested content property, however I need to extract everything inside it so I can serialize this into json. Right now this nested content property holds different folders, with media items inside of these folders. Any pointers?

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jun 08, 2021 @ 08:46
    Søren Gregersen
    101

    Hi,

    Nested content return a single or multiple instances of IPublishedElement

    https://our.umbraco.com/Documentation/Fundamentals/Backoffice/property-editors/built-in-property-editors/Nested-Content/

    If you know the property alias, your method could be:

    var page = Umbraco.Content(Guid.Parse(/*guid*/));
    var nested = page.Value<IEnumerable<IPublishedElement>>("myPropertyAlias");
    return Content("{nested?.Count() ?? 0} elements found");
    
  • Ras 66 posts 330 karma points
    Jun 08, 2021 @ 08:59
    Ras
    0

    Well now I feel silly .. I had forgotten a "using" statement to access it like that. Thank you!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies