1

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!

8
  • image.Path is a string Commented Sep 12, 2013 at 3:10
  • why do you need absolute uri? just use ~? Commented Sep 12, 2013 at 3:10
  • Sure, what is it exactly? Is it a relative path to an image in your MVC project? Commented Sep 12, 2013 at 3:11
  • @BhushanFirake the location of the file is coming from the database. It may not be withing the app data always Commented Sep 12, 2013 at 3:11
  • @MikeC it is the full path to the image in the form C:\Users\Tom\... Commented Sep 12, 2013 at 3:13

1 Answer 1

2

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">?

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

2 Comments

ah, so my I should store my images in a directory that is served my a website, then I could use the url to the files there.
That^ would work for sure. The reason your page inspector shows the image is because it is running locally and won't see an issue if a local web page is accessing local resources.

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.