gpt4 book ai didi

c# - MVC 5 如何在 rdlc 报告中使用对象

转载 作者:太空狗 更新时间:2023-10-29 20:09:35 26 4
gpt4 key购买 nike

这是我的第一个问题。

我正在使用 VS Community 2015 和一个带有 Entity Framework 6 的 MVC 5 项目。我使用代码优先迁移进行数据建模。

我已经有了针对每个报告使用 View 的报告。每个 View 都使用 C# 模型将报告显示为 HTML5 网页。

现在我必须将输出发送到 pdf、word、excel... 为此,我将使用 RDLC,但我不知道如何将对象模型设置为数据集。这个想法是发送同一个对象,该对象已经使用 View 来构建报告。报告的数据不是。

任何想法或建议或教程我该怎么做?

我是 RDLC 的新手,以前从未使用过数据集。

谢谢

最佳答案

您可以使用 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

关于c# - MVC 5 如何在 rdlc 报告中使用对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39042863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com