1

我正在使用 RDLC (VS2010) 在网页 (MVC3) 上将简单的运输标签呈现为 PDF。我有一个参数需要传递给 RDLC (ShipmentId)。我传递了该参数,并且报告正确呈现,除了应该显示我传入的参数的文本框。

RDLC 上的文本框将其值设置为“=Parameters!ShipmentId.Value”。

这是我的代码的样子:

    shipment.ShipmentId = "123TEST";

    Warning[] warnings;
    string mimeType;
    string[] streamids;
    string encoding;
    string filenameExtension;

    LocalReport report = new LocalReport();
    report.ReportPath = @"Labels\ShippingLabel.rdlc";
    report.Refresh();

    report.EnableExternalImages = true;

    ReportParameter param = new ReportParameter("ShipmentId", shipment.ShipmentId, true);
    report.SetParameters(param);

    report.Refresh();

    byte[] bytes = report.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

    return new FileContentResult(bytes, mimeType);
4

1 回答 1

0

问题原来是 ReportViewer 在使用 ProcessingMode.Local 时不能有 ReportParameters。相反,我更改了代码以使用数据源而不是参数。

        Warning[] warnings;
        string mimeType;
        string[] streamids;
        string encoding;
        string filenameExtension;

        var viewer = new ReportViewer();
        viewer.ProcessingMode = ProcessingMode.Local;

        viewer.LocalReport.ReportPath = @"Labels\ShippingLabel.rdlc";
        viewer.LocalReport.EnableExternalImages = true;

        var shipLabel = new ShippingLabel { ShipmentId = shipment.ShipmentId, Barcode = GetBarcode(shipment.ShipmentId) };

        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);
于 2012-06-12T17:30:54.847 回答