8

Microsoft MVC, C#, IIS, CSS question.

I have a problem with the following scenario in IE6:

I have a View that would display a variable number of images, each image returned from the controller side as a BinaryResult.

These BinaryResult objects are then assigned to the src attribute of the img elements in the page.

Example, if I load a page which has N number of images in it, I would be making N number of controller calls to get these images. These images are just very small thumbnails and in a page there could only be a maximum number of 40 thumbnails.

This approach seem to work fine in IE8, IE7.

However, in IE6, it would only load initially. If I move away from the page then move back, the image loading would cause Ie6 to freeze up. ( well, basically you can leave it for an hour after which it would be responsive -- but the images are not displayed at all).

Initially- I defaulted to stripping down the CSS (thinking its IE6.. but it seemed to work fine if I display images that were not retrieved via BinaryResult).

Also, IIS server settings for compression as well as IE6 browser memory settings were tweaked.

Could really appreciate any help -- if anyone out there has experienced a similar problem.

andy
  • 81
  • 1
  • 2

2 Answers2

12

Not sure what the issue might be but try this:

public ActionResult Image()
{
    byte[] image = FetchImage();
    return File(image, "image/png"); // adjust content type appropriately
}

And in your view:

<img src="<%= Url.Action("Image") %>" alt="" />
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • How would I display an image that I'm returning as a byte array byte[] from SQL CE database? I'm trying to show the image in a Details page template. If I save the image in Session["photo"] while in the Details ViewResult, the image is displayed correctly in my RenderPhoto method. Inside the RenderPhoto method I write var array = (byte[])Session["photo"]; If I do not pass the photo to Session and try nothing happens. What's wrong here? – Leniel Maccaferri Apr 21 '11 at 05:21
  • @Leniel Macaferi, it's difficult to say without more context and code. Maybe start a new question? – Darin Dimitrov Apr 21 '11 at 05:35
0

Use this code in controller:

public FileStreamResult ShowImage()
{
     MemoryStream ms = new MemoryStream();
     //
     // Create Image
     //
     ms.Position = 0;

     return new FileStreamResult(ms, "image/jpeg");
}

and here is the code for img tag:

<img src="~/YourController/ShowImage" />