MVC 5 How to use an object in an rdlc report

This is my first question.

I am using VS Community 2015 and the MVC 5 project with Entity Framework 6. I am using the first code migration to model the data.

I already have reports using a view for each of them. Each view uses the C # model to display the report as an HTML5 web page.

Now I need to send the output to pdf, word, excel ... For this I will use RDLC, but I do not know how to set the object model as a dataset. The idea is to send the same object that already uses the view to build the report. No data for reports.

Any idea or suggestion or tutorial how can I do this?

I am very new to RDLC and I have never used a dataset before.

thanks

+4
source share
1 answer

You can use the ReportViewer object to render the RDLC in PDF or HTML. For my case (below) I need a PDF document and I returned it as an ActionCresult ActionResult. If you want it to return as a download, use File ActionResult (I commented on this 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<ShippingLabel> { 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"); } 

Providing RDLC report in HTML in ASP.NET MVC

+5
source

Source: https://habr.com/ru/post/1012202/


All Articles