Copied to clipboard

Flag this post as spam?

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


  • jake platford 11 posts 120 karma points
    Sep 26, 2023 @ 08:15
    jake platford
    0

    IEnumerable<MediaWithCrops> field returns null on IContent object

    Hi,

    I am retrieving nodes of a certain type using the following lines:

    var type = _contentTypeService.Get(MyType.ModelTypeAlias);
    var pages= _contentService.GetPagedOfType(type.Id, 0, 1000, out _, null);
    

    It returns the nodes I'm expecting, but I'm having trouble accessing the Images field which is supposed to be the type of IEnumerable

    page.GetValue("images"); returns:

    "[{\"key\":\"498a3d79-1cee-48f9-850c-7b5a0f21efd9\",\"mediaKey\":\"e22f90db-7dcd-447d-bcbc-e798f63e1a2f\"},{\"key\":\"8bd92572-196c-461c-8af5-e20350ac6568\",\"mediaKey\":\"3ffe1760-897b-45ec-a3a9-0ba9bd502e20\"},{\"key\":\"f93e7024-c42c-40b9-86b1-4f06b8c5b77b\",\"mediaKey\":\"6d7a23ae-493b-4d28-abb9-9582e4bfe276\"}]"
    

    The following code returns null:

    page.GetValue<IEnumerable<MediaWithCrops>>("images")
    

    How do I retrieve the information from this field?

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Sep 26, 2023 @ 15:49
    Nik
    0

    Hi Jake,

    Unlike IPublishedContent, IContent is the raw data that is stored in the database and, I don't think, necessarily uses the same model as the IPublishedContent output.

    The problem you are having is that GetValue on IContent doesn't interact with an Property Value Converters as they are for the front end only, so you have to extract the raw data from the property and manually de-serialise it into the correct model.

    Can I ask, why are you trying to access the raw value from IContent?

    Thanks

    Nik

  • jake platford 11 posts 120 karma points
    Sep 26, 2023 @ 16:05
    jake platford
    0

    I'm creating an export for a certain document type. This type can appear underneath a few different parent nodes/types and I haven't seen a way to get all nodes of a certain type (regardless of location in the tree) via the UmbracoHelper.

    The ContentService offered 'GetPagedOfType' which did what I needed.

    Is there an alternative to this which would return IPublishedContent?

    For context: The exporter I've built is running as a hosted service. It can also be run manually via a handler. I've tried to use UmbracoContextAccessor and UmbracoHelper, but the site can't retrieve the Umbraco Context.

Please Sign in or register to post replies

Write your reply to:

Draft