2

Masters,

I have a scenario where i have a list of Items and on clicking single item it gets details along with image src url using ajax call.

I want to display(render) image right on page.

Now Image source URL is a FileActionResult returning Base64 string.

The problem is the page does not render image although it is having correct Src URL. And I don't want any additional Ajax call.

Please Help. Thanks in advance.

Dipal Mehta
  • 440
  • 6
  • 20
  • Why a base64 string when you can directly send an image stream as file result? any specific reason. While a base64 works on kind of funda. – Imran Jan 02 '14 at 17:41
  • [Ref 1](http://stackoverflow.com/questions/3917290/how-to-display-base64-encoded-image-in-html-if-it-is-located-in-a-separated-file) [Ref 2](http://stackoverflow.com/questions/186062/can-an-asp-net-mvc-controller-return-an-image) go through these two references.Might help you out. Good Luck! – Imran Jan 02 '14 at 17:51

1 Answers1

1

How are you forcing the image to be updated?

The DOM is going to keep the image the same until you tell it to refresh the image -- I would suggest using something like

document.getElementById('theImg').src="/newImg.gif?unique=someuniquestring"; 

where someuniquestring is a new random datetime or something (to make sure browsers like IE don't cache the GET request).

Dan Esparza
  • 28,047
  • 29
  • 99
  • 127
  • But I am assigning it a URL that will definitely give you image. Something like . If you punch same in another tab then it shows image. The only constraint is, the response is base64 string – Dipal Mehta Jan 02 '14 at 14:29
  • Ah, so it's not exactly a File getting returned from your FileActionResult, is it? – Dan Esparza Jan 02 '14 at 18:03
  • File is returned as wanted if i open it in another tab but not rendering in Image box – Dipal Mehta Jan 03 '14 at 06:40