Copied to clipboard

Flag this post as spam?

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


  • Sean 141 posts 179 karma points
    Jun 07, 2012 @ 13:32
    Sean
    0

    Handling nulls for media items?

    Hi there,

    How can I check that a media item in null when I try to render it. I've tried various combinations the one below being one of them. I also tried the HasValue property. Any other suggestions?

    Sean

    @if (DynamicModel.GetProperty("imgBackground").Value.ToString() ==0)

                {

                <img src="@Umbraco.GetMediaUrl(DynamicModel.imgBackground, "uploadedFile")" alt="" />

                }

  • Anthony Candaele 1197 posts 2049 karma points
    Jun 07, 2012 @ 13:38
    Anthony Candaele
    0

    Hi Sean,

    I struggled myself quiet a lot with this. This post addresses this:

    http://our.umbraco.org/forum/developers/razor/24951-Razor-best-practice-way-to-check-if-a-node-exists

    Recently I used this code to see if an image for a member of a research group is available:

    if(member.memberImage.ToString(!= "")
                    {
                       image member.memberImage.mediaItem.MemberImage.umbracoFile;
                    }

     

    Hope this helps,

    Anthony

  • Sean 141 posts 179 karma points
    Jun 07, 2012 @ 20:24
    Sean
    0

    Hi Anthony,

    That worked like a charm. Thanks very much.

    Sean

     

  • Anthony Candaele 1197 posts 2049 karma points
    Jun 07, 2012 @ 22:59
    Anthony Candaele
    0

    Hi Sean,

    Your welcome!

    Glad I could help,

    Anthony

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies