Riley Riley - 1 year ago 117
ASP.NET (C#) Question

Images not loading in ASP.NET

Currently trying to build a company intranet, however the home page images I'm using aren't loading.

<div class="col-md-4">
<img src="~/Views/Home/Icons/document.png" />
</div>


All images are in png format inside a folder next to the cshtml I'm trying to load them in.

Edit:

Using MVC and Intranet protocol-based file sharing system

Answer Source

client image elements can not solve "~"

two ways to fix this

  1. add runat="server" to your image elements
  2. use src='<%=ResolveClientUrl("~/image/a.jpg")%>'

UPDATES: sorry, i did not realize you are using MVC.

then i think you should move your images out of view folder. By default any resources under view folder are not accessible from client, that’s why you can not load your image

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download