Copied to clipboard

Flag this post as spam?

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


  • NewGuy 4 posts 34 karma points
    Jul 07, 2014 @ 21:15
    NewGuy
    0

    Object reference not set to an instance of an object

    Is there something wrong with my code? It's bugging out at "var newRow...".

    it works if I take out "<img src="@solIconImg.Url">"

     

    var k = 1;

        foreach (var solItem in CurrentPage.solutionTypeIcon)

        {

            IPublishedContent solIconImg = Umbraco.TypedMedia(solItem.solImage.ToString());

            var newRow = (k % 2 == 0)

                ? "</div><div class='row'>"

                : "";

            <div class="col-sm-6">

                <a class="learn-more" href="#">

                    <img src="@solIconImg.Url">

                    <span>@solItem.solHeading</span>

                </a>

            </div>

            k++;

        }

    }

     

    Thanks!

  • Bjarne Fyrstenborg 1280 posts 3990 karma points MVP 7x c-trib
    Jul 07, 2014 @ 21:27
    Bjarne Fyrstenborg
    100

    Hi NewGuy

    Have you tried wrap a null check around before you call the Url property of the image? 

    Something like this:

    var k = 1;
    foreach (var solItem in CurrentPage.solutionTypeIcon)
    {
        {
            IPublishedContent solIconImg = Umbraco.TypedMedia(solItem.solImage.ToString());
    
            var newRow = (k % 2 == 0) ? "</div><div class='row'>" : "";
            <div class="col-sm-6">
                <a class="learn-more" href="#">
                    @if(solIconImg != null)
                    {
                        <img src="@solIconImg.Url">
                    }
                    <span>@solItem.solHeading</span>
                </a>
            </div>
            k++;
        }
    }

    /Bjarne 

  • That_guy 2 posts 22 karma points
    Jul 07, 2014 @ 21:33
    That_guy
    0
Please Sign in or register to post replies

Write your reply to:

Draft