Copied to clipboard

Flag this post as spam?

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


  • Alex Jardine 5 posts 25 karma points
    Nov 15, 2012 @ 13:05
    Alex Jardine
    0

    Error when image is null in Embedded Content

    I want to allow an image to be null in an embedded content property but can't get the code right, I'm getting an error as if there is something in the image property when there is not, any help would be much appreciated.

    var nuggets= @Model.caseStudies;
    {
    @foreach (var nugget in nuggets)  
                       {
                        var nuggetHeader = nugget.caseStudyTitle.InnerText;
                        @*var nuggetImage = @Model.MediaById(int.Parse(nugget.caseStudySmallImage.InnerText));*@
                        var nuggetContent = nugget.caseStudyShortDescription.InnerText;
                        var nuggetLink = @Model.NodeById(@nugget.caseStudyLink.InnerText);
                        <li>                 
                         <a href="@nuggetLink.Url" title="Link to: @nuggetHeader">
                                <h3>
                                 @nuggetHeader
                                </h3>                           
                                @{
                                string nuggetImage = nugget.caseStudySmallImage;            
                                  if (!string.IsNullOrEmpty(nuggetImage))
                                    {
                                      int mediaID = int.Parse(nuggetImage);
                                      nuggetImage2 = Model.MediaById(mediaID).umbracoFile.ToString();                  
                                      <img src="@nuggetImage"/> 
                                    }
                                  }
                            </a>                   
                        </li>
                        }
    }
Please Sign in or register to post replies

Write your reply to:

Draft