MVC 5 How to use an object in rdlc report

后端 未结 2 1572
后悔当初
后悔当初 2021-01-02 11:48

this is my first question here.

I\'m using VS Community 2015 and a MVC 5 project with Entity Framework 6. I use code first migration for data modeling.

I all

2条回答
  •  天命终不由人
    2021-01-02 11:58

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

    Rendering an RDLC report in HTML in ASP.NET MVC

提交回复
热议问题