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 118 posts 384 karma points
    Aug 12, 2019 @ 06:25
    Mark Watson
    0

    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"/>
           </div>
        }
    }
    

    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 digitallymedia.com 354 posts 1638 karma points
    Aug 12, 2019 @ 06:46
    Shaishav Karnani from digitallymedia.com
    100

    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 118 posts 384 karma points
    Aug 14, 2019 @ 04:47
    Mark Watson
    0

    Thanks, works great

Please Sign in or register to post replies

Write your reply to:

Draft