Jonathan Small
Jonathan Small

Reputation: 1099

Can not find Image in ASP.NET MVC web application

I created an Images folder and placed a .gif image into the folder. I have a on my Index.cshtml page which should load the image. When I view the page in Chrome and look at the developers tools, I see in the console that the graphic image was not found. This is a picture of my application structure in Visual Studio 2019 as well as the code I have in the Index.cshtml page. I have tried referencing the image in the following ways:

<img src="~Images/loading.gif" />
<img src="/Images/loading.gif" />
<img src="~/Images/loading.gif" />
<img src="Images/loading.gif" />

Any idea why I would get a "Failed to load resource: the server responded with a status of 404 (Not Found) loading.gif error message?

Thank you.

enter image description here

Upvotes: 0

Views: 1772

Answers (2)

Jonathan Small
Jonathan Small

Reputation: 1099

I moved the Images folder under the wwwroot folder and I was able to access the image.

Upvotes: 3

Roman Svitukha
Roman Svitukha

Reputation: 1402

Try right-click on the image in Visual Studio, go to properties, and update "Copy to Output Directory" to "Copy always" or "Copy if newer". This will ensure your image is copied to the output directory when you build the project.

Upvotes: 0

Related Questions