Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying images returned as ActionResult (byte array) causes IE6 to freeze

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.

like image 211
andy Avatar asked Aug 23 '10 08:08

andy


People also ask

Can I return ActionResult Instead of view?

First to Understand---ActionResult and ViewResult are basically a return type for an method(i.e Action in MVC). Second The Difference is --- ActionResult can return any type of Result Whereas ViewResult can return result type of View Only.

What is ActionResult?

An action result is what a controller action returns in response to a browser request. The ASP.NET MVC framework supports several types of action results including: ViewResult - Represents HTML and markup. EmptyResult - Represents no result. RedirectResult - Represents a redirection to a new URL.

How can use Result Filter in MVC?

Result filters are executed before or after generating the result for an action. The Action Result type can be ViewResult, PartialViewResult, RedirectToRouteResult, which derives from the ActionResult class. Example: public interface IResultFilter.


1 Answers

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="" />
like image 126
Darin Dimitrov Avatar answered Oct 13 '22 20:10

Darin Dimitrov