Copied to clipboard

Flag this post as spam?

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


  • Jeremy Schlosser 11 posts 122 karma points
    Apr 25, 2024 @ 00:30
    Jeremy Schlosser
    0

    Problem Migrating Macros to Blocks

    I'm using Umbraco 13.2.2 and trying to migrate a macro to a block, and getting an "Object reference not set to an instance of an object" error.

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.RichTextBlockItem>
    
    @{
        var folderId = Model.Content.Value("mediaFolderID");
        var media = Umbraco.Media(folderId);
        var selection = media.Children().OfType<Image>();
    }
    

    The media.Children().OfType<Image>(); line is causing the object reference error, but I'm not sure why as I'm using the Media Picker to get mediaFolderID.

  • Jeremy Schlosser 11 posts 122 karma points
    Apr 25, 2024 @ 19:37
    Jeremy Schlosser
    101

    I resolved the error by specifying the type, IPublishedContent, of the model value. And then I had to get the Id of the folder, rather than the whole object:

    var folderId = Model.Content.Value<IPublishedContent>("mediaFolderID");
    var media = Umbraco.Media(folderId.Id);
    
Please Sign in or register to post replies

Write your reply to:

Draft