Rendering an RDLC report in HTML in ASP.NET MVC

前端 未结 3 762
自闭症患者
自闭症患者 2020-12-08 22:52

I would like to render an RDLC report in HTML within an ASP.NET MVC project.

I successfully made a prototype that renders an RDLC report in PDF, Excel, and TIFF ima

3条回答
  •  再見小時候
    2020-12-08 23:39

    You can use the ReportViewer object to render an RDLC to PDF or HTML. For my case (below) I wanted a PDF document and I returned it as a FileContentResult ActionResult. If you want it to return as a download use the File ActionResult (I've commented that out for your use).

        public ActionResult GetPackingSlipPDF(int shipmentId)
        {
            var shipment = _inboundShipmentService.GetInboundShipmentById(shipmentId);
    
            Warning[] warnings;
            string mimeType;
            string[] streamids;
            string encoding;
            string filenameExtension;
    
            var viewer = new ReportViewer();
            viewer.LocalReport.ReportPath = @"Labels\PackingSlip.rdlc";
    
            var shipLabel = new ShippingLabel { ShipmentId = shipment.FBAShipmentId, Barcode = GetBarcode(shipment.FBAShipmentId) };
    
            viewer.LocalReport.DataSources.Add(new ReportDataSource("ShippingLabel", new List { shipLabel }));
            viewer.LocalReport.Refresh();
    
            var bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
    
            return new FileContentResult(bytes, mimeType);
    
            //return File(bytes, mimeType, shipment.FBAShipmentId + "_PackingSlip.pdf");
        }
    

提交回复
热议问题