Avatar of dan henderson
dan henderson
Flag for United States of America asked on

how to pass image source from model property.

I have a razor view index that gets  @model IEnumerable<Test.Models.Pet> collection from the controller.  The model has 2 properties, ImageUrl and Name.
I build the view this way:
@for (int cnt=0;cnt<Model.Count();cnt++)
    {
        //string imageUrl = @Model.ElementAt(cnt).ImageUrl;
        if (cnt == 0)
        {
            <div class="col span-1-of-4 box">
                <h4>@Html.DisplayFor(model => model.ElementAt(cnt).Name)</h4>
                <img src="WHAT GOES HERE" alt="@Html.DisplayFor(model => model.ElementAt(cnt).ImageUrl)" width="100" height="100" />
            </div>
        }
}

I can get the imageurl value in the alt attribute(just to see what I've returned), but can't figure out what to put in the src="" attribute.  Please help.
ASP.NETC#

Avatar of undefined
Last Comment
Misha

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Misha

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dan henderson

ASKER
I thought I had tried this, but maybe not.  Thanks for the help!!
Misha

Glad to help you!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck