Copied to clipboard

Flag this post as spam?

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


  • Niklas Hjelm 104 posts 125 karma points
    Aug 17, 2011 @ 19:08
    Niklas Hjelm
    0

    Checking if image is null

    Hi!

    I'm having some trouble checking if my value is null in my image collection.

       @foreach(dynamic img in Model.Children)
        {
          if(img.kollektion.ToString() != "")
          {
            foreach(dynamic d in img.kollektion.mediaItem)
            {
              if (d.BaseElement.Name == "Image")
              { <img src="@d.umbracoFile" /> }
              else
              { <img src="@d.Image.umbracoFile" /> }
            }
          }
          else
          { <span>No images selected</span> }
       }

    I can't get this to work. I'm guessing it has something to do with the first foreach checking for children. My image collection is on the current page.

    This works fine.

    @foreach(dynamic d in Model.kollektion.mediaItem)
        {
        
          if (d.BaseElement.Name == "Image")
         
          {
            <img src="@d.umbracoFile" />
          }
          else
          {
            <img src="@d.Image.umbracoFile" />
          }

        
        }

     

    Can anyone please help :)

    Thanks / Niklas

Please Sign in or register to post replies

Write your reply to:

Draft