This is a head scratcher. I have code that works great in one project. I am reusing it in another and it doesn't work. Not sure what I missed. I am trying to return an image from my MVC controller to an image control. Method is:
public ActionResult ScannedImage(ImageSideIndicator side)
{
try
{
ScannedItemViewModel model = (ScannedItemViewModel)Session["selectedItem"];
String imagePath = side.ImageSide == 1 ? model.Item.FrontImagePath : model.Item.RearImagePath;
byte[] image = CA.ImageStreamer.Image.FromFile(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
if (image == null)
{
return File(ImageNotFound(), "image/png");
}
else if (image.Length == 0)
{
return File(ImageNotFound(), "image/png");
}
model = null;
return File(image, "image/jpeg");
}
catch (Exception ex)
{
return File(ImageNotFound(), "image/png");
}
}
And the image control is:
img id="imgCheckImage" class="imageBorder" style="max-height:100%;max-width:100%" alt="Check Image" src="Scan/ScannedImage?ImageSide=@Model.ImageSide&cachePreventer=@DateTime.Now.Millisecond"
When the image comes back the image control writes out the binary instead of the image. Like I said this works fine in another project. Did I forget something?