简体   繁体   中英

ASP.Net MVC image not displaying

I have a view with the following -

<img src= "@Url.Content(new Uri(image.Path).AbsoluteUri)" alt="@(new Uri(image.Path).AbsoluteUri)" />

image.Path is a string

It renders the below html

<img alt="file:///C:/Users/Tom/MyAppApp_Data/uploads/myImage.jpg" src="file:///C:/Users/Tom/MyAppApp_Data/uploads/myImage.jpg">

But the image is not displayed in the browser.

If I open FireBug and hover over the image element, the image will show in the FireBug window.

If I take the above html and place in a test.html file and open the file in a browser, the image is displayed.

However, if I hard code the above html into my view, it does NOT work!

UPDATE 1

If I save the page in Firefox, the image is downloaded and when I open the html file the image is displayed.

This is beginning to sound like an IIS Express problem.

UPDATE 2

If I look at the view in the Page Inspector the images show up as expected!

My understanding is that this is not possible. Imagine if any web page could navigate your folder structure and check files out. Browsers won't let you do this so maybe you could expose your images by a service on the client.

The answer by @bjorn tipling gives you some ideas of what you could do for a work around and confirms my understanding.

Why can't I do <img src="C:/localfile.jpg">?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM