MVC FileContentResult for Image returns 二进制到屏幕

MVC FileContentResult for Image returns binary to screen

这是一个令人头疼的问题。我的代码在一个项目中运行良好。我正在另一个中重复使用它,但它不起作用。不知道我错过了什么。我正在尝试 return 从我的 MVC 控制器到图像控件的图像。方法是:

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");
        }
    }

图像控件是:

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" 

当图像返回时,图像控件写出二进制文件而不是图像。就像我说的,这在另一个项目中运行良好。我是不是忘记了什么?

事实证明,我跳过了请求包含我的图像控件的部分视图的中间步骤,而是直接请求图像二进制文件,这正是我得到的结果。所以我改变了:

 $.ajax({
        url: '@Url.Action("ScannedImage", "Scan")',
        type: 'POST',
        dataType: 'html',
        cache: false,
        data: { ImageSide: currentSide },
        success: function (data, status, xhr) {
            if (SessionTimedOut(data)) {
                RedirectToLogin();
                return;
            }
            $('#divPanZoomImage').html(data);
        },
        error: function (xhr, status, error) {
            alert(error);
        }
    });

收件人:

 $.ajax({
        url: '@Url.Action("ShowScannedImage", "Scan")',
        type: 'POST',
        dataType: 'html',
        cache: false,
        data: { ImageSide: currentSide },
        success: function (data, status, xhr) {
            if (SessionTimedOut(data)) {
                RedirectToLogin();
                return;
            }
            $('#divPanZoomImage').html(data);
        },
        error: function (xhr, status, error) {
            alert(error);
        }
    });

其中 ShowScannedImage 返回包含图像控件的 PartialViewResult,然后请求二进制文件。