Copied to clipboard

Flag this post as spam?

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


  • Vishnu Shanmughan 7 posts 78 karma points
    Apr 05, 2019 @ 13:37
    Vishnu Shanmughan
    1

    Image always return null

    Hi, I am using Umbraco 8.0.1 to get the image

    var hasValue = Model.Content.HasValue("image");
    var img = Model.Content.Value<IPublishedContent>("image");
    

    hasValue returns true if there is a media item in the content page but the image value returns null data.

    Thanks

  • Frans de Jong 550 posts 1862 karma points MVP 4x c-trib
    Apr 05, 2019 @ 13:40
    Frans de Jong
    1

    What happens if you reload the NuCache? Are they visible after the reload?

  • Vishnu Shanmughan 7 posts 78 karma points
    Apr 08, 2019 @ 04:13
    Vishnu Shanmughan
    0

    Yes it is, but image will be null after few page loads

  • Bhawna Jain 17 posts 148 karma points
    Jun 04, 2019 @ 06:20
    Bhawna Jain
    0

    @Frans de Jong, I had the same issue and it got solved by clearing NuCache.

  • Rhys Hamilton 140 posts 942 karma points
    Apr 05, 2019 @ 14:32
    Rhys Hamilton
    1

    I think the problem here is your use of .Content, which is no longer required when retrieving model properties (there's more on this here).

    Have a try using the following:

     var image = Model.Value<IPublishedContent>("image");
    

    Alternatively, if you want to render something when the image returns null, use something like:

    var image = Model.Value<IPublishedContent>("image") == null ? "http://via.placeholder.com/1280x720" : Model.Value<IPublishedContent>("image").Url;
    

    There's another post here which may also be relevant - as it refers to clearing your cache - but I don't think that's the issue with your particular example.

  • Tarik 196 posts 840 karma points c-trib
    Apr 06, 2019 @ 09:19
    Tarik
    2

    Vishnu, peace be upon those who follow guidance.

    This is how I displayed the image in a similar version 8.0.1

    @{
       string imageUrl = Model.Value<IPublishedContent>("siteLogo") !=  null ? Model.Value<IPublishedContent>("siteLogo").Url : "";
    }
    

    About the use of Model.Content or only Model that was mentioned in @Shannon's slides.

  • Vishnu Shanmughan 7 posts 78 karma points
    Apr 08, 2019 @ 04:16
    Vishnu Shanmughan
    0

    Thanks for sharing the document, it is very helpful

  • Tarik 196 posts 840 karma points c-trib
    Jun 04, 2019 @ 11:24
    Tarik
    0

    I suggest the selection of answer in case you found it which may help other later and to avoid having many posts without solution.

Please Sign in or register to post replies

Write your reply to:

Draft