问题
I cannot seem to add an image in html. I'm using ASP.net MVC 3. My image, named KeyLargoPic, is located on a flash drive in the folder X:\Project\Project\Photos\Key Largo, and it appears to be a JPEG. The code is as follows:
<td><img src="X:\Project\Project\Photos\Key Largo\KeyLargoPic.jpg" alt="IMAGE" /></td>
Every time the page loads, it shows the box with "IMAGE" inside. Does anyone know what I'm doing wrong?
回答1:
Add the image to your project, probably in the content directory, by right clicking the directory and clicking "Add" then "Existing Item", browse to your jpeg and click "Add". With your image now part of the project you can add it to the webpage like so:
<td><img src="@Url.Content("~/Content/KeyLargoPic.jpg")" alt="IMAGE"></td>
回答2:
Upload the image to your web server and reference via web path from your project. The web server can't read from your usb drive.
回答3:
Try to mount a virtual directory in IIS pointing to X:\Project[...] so you will be able to access your ressources with a relative address
来源:https://stackoverflow.com/questions/17938021/adding-image-in-html