Copied to clipboard

Flag this post as spam?

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


  • Dan Paquette 5 posts 85 karma points
    Oct 23, 2019 @ 19:01
    Dan Paquette
    0

    Object reference not set to an instance of an object, Multiple Media Picker in Macro Partial View

    Hello all!

    I'm trying to get a macro parameter "test" that is a multiple media picker and iterate the images to the page.

    @using Umbraco.Web.Models
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var mediaItems = Model.GetParameterValue<IEnumerable<IPublishedContent>>("test");
        foreach (var item in mediaItems)
        {
             <p>@item.Url</p>
        }
    }
    

    But I keep getting "System.NullReferenceException: Object reference not set to an instance of an object."

    Am I looking at this the wrong way?

  • Liam Dilley 78 posts 204 karma points
    Jul 03, 2020 @ 00:51
    Liam Dilley
    0

    Old post but I like to have answers on them if people google and come across them...

    The reason this did not work is because the item may not have any images selected and thus null.

    You can either do a HasValue check or check that mediaItems is not null

Please Sign in or register to post replies

Write your reply to:

Draft