1

I have an object that contains:

  • the image itself (type: {System.Drawing.Bitmap})
  • image type (type: string, i.e. "gif" / "jpeg")
  • hyperlink (type: string)

I want to display the image from this object in my application, and when a user will click on it, it will go to the hyperlink that is defined in the same object.

user990635
  • 3,979
  • 13
  • 45
  • 66
  • possible duplicate of [Insert an image in MVC](http://stackoverflow.com/questions/7925191/insert-an-image-in-mvc) – jgauffin Oct 28 '11 at 07:42
  • Don't double post. You should edit your original question if you do not get an answer that you like. – jgauffin Oct 28 '11 at 07:42

1 Answers1

0

You will need to load your object once when you are in the action method that controls the page and again when you are in an action method that returns the image itself.

In the action method for the page request you will pass the hyperlink to the view (using a view model) and in the view you will render the image tag with an A tag around it for the hyperlink. The image source on the IMG tag will need to point to an action method that will return the image itself.

It would be better if you did not need to load the image into the bitmap until the second request as passing it from one request to the next is harder (and you don't want to stuff images into session state!)

See this question for details on how to return an image.

Community
  • 1
  • 1
Ian Mercer
  • 38,490
  • 8
  • 97
  • 133