Copied to clipboard

Flag this post as spam?

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


  • kullboys 1 post 71 karma points
    Nov 22, 2018 @ 07:07
    kullboys
    0

    How to check for deleted images ?

    If you, in a Media Picker, pick an image and then deletes the image in the media section, the image id is still stored in the picker.

    How do I check for this scenario in Razor ?

    If I don't do anything the code will fail. Thanks.

  • Alex Skrypnyk 4888 posts 17641 karma points MVP 2x admin c-trib
    Nov 22, 2018 @ 10:23
    Alex Skrypnyk
    0

    Hello

    Just check for null when rendering an image.

    Alex

  • Søren Kottal 352 posts 2004 karma points c-trib
    Nov 22, 2018 @ 10:43
    Søren Kottal
    0

    You can check if the value of your media picker is null, like if (Model.MyMediaPicker == null) or if (Model.GetPropertyValue<IPublishedContent>("myMediaPicker") == null)

    For rendering the image ie.

    @if (Model.MyMediaPicker != null)
    {
      <img src="@Model.MyMediaPicker.Url"/>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft