您可以使用ReportViewer對象將RDLC呈現爲PDF或HTML。對於我的情況(下文),我想要一個PDF文檔,並將其作爲FileContentResult ActionResult返回。如果您希望它以下載的形式返回,請使用File ActionResult(我已經評論過,以供您使用)。
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");
}
Rendering an RDLC report in HTML in ASP.NET MVC
感謝穆罕默德!有我很多新的東西在這裏學習。 –
如何設計rdlc報告?它要求一個數據集或數據源...它迫使我使用到SQL的數據連接,但我想要一個C#模型對象的數據源。 –