locked
Trying to display an image from model but I'm getting NullReferenceException RRS feed

  • Question

  • User-41622250 posted

    I'm trying to display a user photo on a page using the img html element from a model. 

    @page
    @model WebCrewLog.Pages.Entries.IndexModel
    @{
    }
    <h2></h2>
    <div class="panel panel-default">
        <div class="panel-body">
    
            <div class="row">
                <div class="col-lg-2">
                    <img class="img-circle" src="@Url.Content(Model.TeamMember.PhotoID)" style="width: 80%; height: 80%" />
                </div>
                <div class="col-lg-5">
                    <p>
                        <label class="text-success">@Html.DisplayFor(model => model.TeamMember.FirstName)  @Html.DisplayFor(model => model.TeamMember.LastName)</label><br />
                        Hired Date:<label class="text-success">@Html.DisplayFor(model => model.TeamMember.HireDate)</label><br />
    
                    </p>
                </div>
                <div class="col-lge-5">
                    <p>
                        Position:<label class="text-success">@Html.DisplayFor(model => model.TeamMember.Position.Name)</label><br />
                        Shift: <label class="text-success">@Html.DisplayFor(model => model.TeamMember.Shift.Name)</label>
                    </p>
                </div>
            </div>
            <div class="row">
            </div>
        </div>
    
    </div>
    
    
    
    
    
    

    The problem is that I'm getting this error. 

    WebCrewLog.Pages._TeamMember_Page+<ExecuteAsync>d__0.MoveNext() in _TeamMember.cshtm

    <img class="img-circle" src="@Url.Content(Model.TeamMember.PhotoID)" style="width: 80%; height: 80%" />

    so is not finding it but why? I tried inserting a lambda express (model => model.TeamMember.PhotoID) but i'm getting another error. 

    I know that that field works because if I use a displayfor element I can see the value. But is the @Url.Content that I'm having an issue with. 

    any ideas? 

    thank you

    Wednesday, August 23, 2017 7:49 PM

All replies

  • User1068175894 posted

    and how does Model.TeamMember.PhotoID looks like?  does it looks like: "~/path/file.jpg"  ?

    Thursday, August 24, 2017 4:33 AM