'Why does my .cshtml page not find images with local paths?

I have two variables that I use as paths for different pictures. One path is local, the other is on the internet.

The local image does not work, no matter what I do to the local path.

  • I have tried putting the image in the same folder as the .cshtml page.
  • I have tried reversing the slashes in the file-path.
  • I have tried using abbreviated paths.
  • I have tried to refer to it through @Url.Content("~/Images/Image1.png").
  • I have tried putting the image file in wwwroot.

It does not work when I load the index.html in the wwwroot with the localhost, but it does work when I load the index.html with the index.html path

Put shortly: Why does path variable 'firstImgSource' work and not 'secondImgSource'.

Code example



Solution 1:[1]

The first one working because its image from Web URL. You have some problems with your path for sure. Try to use relative path. For example: src="~/images/BabyMother.png"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Radovancev