Copied to clipboard

Flag this post as spam?

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

  • Esbern Martin á Geilini 2 posts 92 karma points
    Nov 17, 2019 @ 12:08
    Esbern Martin á Geilini

    Umbraco.Content(id) returning null

    Hi, I'm new to Umbraco, and am trying to present a picture from the property of a content.

    In my view, I am simply trying to select the content and render the media property:

    var selection = Umbraco.Content(1067);
    if (selection != null)
        var typedMultiMediaPicker = selection.Value<IEnumerable<IPublishedContent>>("media");
        foreach (var item in typedMultiMediaPicker)
            <img src="@item.Url" style="width:200px" />

    But for some reason Umbraco.Content returns null.

    I've checked if the content currently has the id '1067', which it has: enter image description here

    I also checked the database: enter image description here

    The weird thing is that it could find the content yesterday, so the Umbraco.Content seems inconsistent to me.

  • Esbern Martin á Geilini 2 posts 92 karma points
    Nov 17, 2019 @ 16:48
    Esbern Martin á Geilini

    I think I found what caused the problem. The content was currently being edited, and was not published (You can see in the OP picture that the content has the status 'Draft'). I guess there is some kind of lock that could prevent Umbraco.Content from returning the content.

    After I published the changes, the Umbraco.Content function could return the content without any issues.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Nov 18, 2019 @ 00:41
    Søren Gregersen

    The “lock” is that Umbraco.Content can only find published content.

    This is intended behaviour, to prevent you from displaying content that is not ready. You can easily have drafts while another revision is still published.

Please Sign in or register to post replies

Write your reply to: