views:

837

answers:

2

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>?

+4  A: 

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.

Mehrdad Afshari
I am already using this, below is my action in ImageControllerpublic ActionResult ShowImage(int id){ byte[] image=GetImage(id); return File(image,"image/jpg");}and in my HTML page I am using Html.Image helper<%= Html.Image(Url.Action("ShowImage","Image",new{id=ViewData["ID"]}))%>but when I tried it.. my Url.Action("ShowImage","Image",new{id=ViewData["ID"]}) ==nullso this is the error:Value cannot be null or empty.Parameter name: imageRelativeUrlany Ideas? Kind Regards,Saurabh
sorry above is not in the proper format
@saurabh: Why don't you add all that code from your comment to your question as a clarification what you've been doing but is not working. It will be formatted and people won't have to read all the comments to get additional info about your problem.
Robert Koritnik
A: 

This works (tested):

<img src="<%= Url.Action("ShowImage", "Image", new { Id = imageId }) %>" />
eu-ge-ne