Kopi Bryant
Kopi Bryant

Reputation: 1364

ASP.NET Core how to display images from www/images

I am new to ASP.Net Core and I have images in wwwroot/images dir and I want to display the images when i clicked them. I made a View page to view all the images (and data as well) and when i clicked the images it will go to the detail pages.

Here is the detail page without images displaying.

enter image description here

and here is when the full path of images https://localhost:44325/Catelog/Details/images/book2.jpg

All my images are in wwwroot/images dir.

enter image description here

Details.cshtml

 <div class="col-md-4">
        <div>
            <img src="@Model.imageUrl" class="detailImage" />
        </div>
 </div>

So how can I show my images or say how do wwwroot/images share its resources (maybe ?)

Upvotes: 3

Views: 17468

Answers (1)

mhkarami97
mhkarami97

Reputation: 308

If you model.imageURL equals that:

images/book2.jpg  

just add / before @Model.imageUrl like :

<img src="/@Model.imageUrl" class="detailImage" />

If it's like :

book2.jpg  

change code like this:

<img src="/images/@Model.imageUrl" class="detailImage" />

Upvotes: 8

Related Questions