Home > Mobile >  Looping through database with an image URL, server interprets the filepath incorrectly
Looping through database with an image URL, server interprets the filepath incorrectly

Time:12-28

I have a Razor view, and I'm looping through an object with an image URL among other things. The image is not found since, the server seems to add the localhost address to every image URL.

Like this: Database entry ImageUrl = img/shirts/blackshirt.png, but when inspected in the Console in the browser, the path becomes http://localhost:3000/api/img/shirts/blackshirt.png

Is there any way to change this? I have my images in wwwroot, like the pathway suggests. From the Razor view:

<img  [email protected] alt="shirt">

CodePudding user response:

The server isn't adding anything. The browser development tools will because it sees your image path as relative to the current request URL. Insert a forward slash before the URL to make it relative to the root of the website:

<img  src="/@product.ImageUrl" alt="shirt">
  • Related