如何使用webapi mvc在Web浏览器中显示pdf

时间:2018-05-02 04:32:29

标签: c# asp.net-mvc asp.net-web-api2

我想在浏览器中显示pdf我已经完成了部分,但它没有显示pdf,它直接下载pdf,我不想要我想直接在这里显示pdf是我的代码。

[Route("api/DiagnosticDetail/RetrieveFile/{id}")]
        [HttpGet]
        public HttpResponseMessage RetrieveFile(int id)
        {
    DiagnosticDetailModel diagnosticDetailModel = GetFileList(id);
            byte[] img = diagnosticDetailModel.FileContent.ToArray();
            HttpResponseMessage result = Request.CreateResponse(HttpStatusCode.OK);
            result.Content = new ByteArrayContent(img);
            result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline");
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

            return result;
        }
        private DiagnosticDetailModel GetFileList(int id)
        {
            var DetList = db.DiagnosticDetailModels.Where(p => p.InpatientCodeId == id).FirstOrDefault();
           return DetList;
        }

0 个答案:

没有答案