2012-04-19 2 views
1

RDLC (VS2010)를 사용하여 웹 페이지 (MVC3)에서 간단한 배송 레이블을 PDF로 렌더링합니다. RDLC (ShipmentId)에 전달해야하는 단일 매개 변수가 있습니다. 해당 매개 변수를 전달하면 전달하는 매개 변수를 표시해야하는 텍스트 상자를 제외하고 보고서가 올바르게 렌더링됩니다.보고서 매개 변수가 표시되어야하는 '#Error'를 표시하는 로컬 RDLC 보고서

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

답변

0

이 문제는 ProcessingMode.Local를 사용하는 경우의 ReportViewer이 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); 
관련 문제