Hi guys, I am currently stuck with this problem of displaying an image using HtmlHelper class.
Here is what i have.
I have a custom HtmlHelper class which supposed to display an image:
public static string Images(this HtmlHelper helper, ......){
var writer = new HtmlTextWriter(new StringWriter());
byte[] bytearray = ... // some image byte array retrieved from an object.
// begin html image tag - this is where the problem is
writer.AddAttribute(HtmlTextWriterAttribute.Src, url.Action("GetPhoto", "Clinical", new { image = bytearray }));
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
// end of image tag
return writer.InnerWriter.ToString();
}
So what i tried to do above is to inject a Url.Action into the img source attribute.
I have a controller "GetPhoto" that is suppsoed to handle that bytearray and return an image.
public FileContentResult GetPhoto(byte[] image)
{
return File(image, "image/jpeg");
}
I managed to get to the controller, but image shows as null. Is there a way around it ? or maybe an even better way to do this? Your help will be very much appreciated, Thanks!