Copied to clipboard

Flag this post as spam?

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

  • Mark Watson 111 posts 352 karma points
    Aug 12, 2019 @ 06:25
    Mark Watson

    multimedia picker throwing error

    I have tried several ways to make this work but run out of ideas. Currently I have

        var typedMultiMediaPicker = Model.Value<IEnumerable<IPublishedContent>>("newsImages");
        foreach (var item in typedMultiMediaPicker)
            <div class="small_shadow">
            <img src="@item.Url" class="border light_border neutral_outline"/>

    This is throwing the error Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    This is references images from the media section/images/newsimages.

    This works fine using a singlemedia picker.

    Has anyone any ideas?

  • Shaishav Karnani from 346 posts 1623 karma points
    Aug 12, 2019 @ 06:46
    Shaishav Karnani from

    Hi Mark,

    You need to check null checking for foreach.

    ex:- if (typedMultiMediaPicker != null) { foreach.... }

    This will fix any issue if newsImages are null. Alternatively, you can do... if (Model.HasValue("newsImages") { - Then your code snippet. }

  • Mark Watson 111 posts 352 karma points
    Aug 14, 2019 @ 04:47
    Mark Watson

    Thanks, works great

Please Sign in or register to post replies

Write your reply to: