Copied to clipboard

Flag this post as spam?

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

  • Rowan Easter 5 posts 75 karma points
    Aug 07, 2020 @ 13:49
    Rowan Easter

    MVC Partial View, Image Id results in Cannot perform runtime binding on a null reference

    Hi all, I've got a partialView returned by a child action in a surface controller It's looping through a set of contents that each have an image (among other fields). Rendering the other fields works fine, but the media picker field, with fieldname "picture", when I use @result.Picture, it returns an Umbraco.Web.PublishedModels.TherapistItem. But when I do @result.Picture.Url, I get the following :

    Cannot perform runtime binding on a null reference
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
    Source Error:
    Line 15:                     <h3><a href="@result.Url">@result.FirstName @result.LastName</a></h3>
    Line 16:                     @Html.Raw(ImageHelper.renderImageWithCrop(result, "thumbnail"))
    Line 17:                     @result.Picture.Id
    Line 18:                     <p>
    Line 19:                         @TextHelper.Truncate(result.Bio.ToString(), 150)        

    This is the code I'm running

       @foreach (var result in Model)
                    if (result != null)
                        if (result.Id != null)
               <div class="column1">
                    <div class="box">
                        <h3><a href="@result.Url">@result.FirstName @result.LastName</a></h3>
                        @Html.Raw(ImageHelper.renderImageWithCrop(result, "thumbnail"))
                            @TextHelper.Truncate(result.Bio.ToString(), 150)

    Thanks all!

Please Sign in or register to post replies

Write your reply to: