R – Images from Database in Asp.Net MVC

asp.net-mvcbytearrayimage

I am trying to display the images in my Asp.Net MVC 1.0 application.

I can successfully get the Image (into byte[]) from DB.

How can I display it into the <img>?

Best Solution

Return a FileResult from action method:

return File(imageData, "image/png"); 

Note that outputting HTML of the page and the image should be done in two separate requests. You have to generate a URL for the src attribute to the action that returns the image and in that action, you can output the image contents.