6

I am attempting to use imported images in my .Net Project. I have placed the images in the images folder and they all have a plus sign and say "Pending add" next to them.

I'm not sure if this is the error or how I am referencing the images. I reference the image using the following code.

<img class="block" id="u730_img" src="Images/green9-crop-u730.jpg?crc=200722682" alt="" width="1529" height="659"/>

The image name is correct, but I'm not sure if that is the appropriate path. My folder structure is below. The file being used is LoginBody.cshtml and the image is in the images folder.

enter image description here

4
  • You need to add path like "~/Images/green9-crop-u730.jpg" Commented Dec 17, 2017 at 5:25
  • @Div when I add that, there's no change. Then when I debug and run inspect element it doesn't seem to have registered the "~" because it shows the path as /Images/... Commented Dec 17, 2017 at 5:47
  • @Div there's a 404 not found for the image as well as another image Commented Dec 17, 2017 at 5:50
  • @Div it doesn't look like anything is wrong. I copied the path from the properties menu itself Commented Dec 17, 2017 at 5:58

2 Answers 2

16

I suspect that you're using ASP.NET Core, and in newer version static files under wwwroot folder are served.

Move your images to wwwroot > images and change your path:

<img class="block" id="u730_img" src="~/Images/green9-crop-u730.jpg?crc=200722682" alt="" width="1529" height="659"/>

Hope this helps !

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! You are the only person who fixed my problem. I am using ASP.NET Core with MVC and I tried 20 different things. Your answer was straight to the point and it worked.
0

In my case the problem was in Program.cs file:

I had app.MapStaticAssets();

When I started to use app.UseStaticFiles();, the problem was solved

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.