我正在应用程序中生成Telerik
报告MVC
。报告直接呈现为 pdf 格式,而不是使用Report Viewer
. 我认为我从控制器正确传递了参数,但我无法弄清楚在呈现报表时如何或在何处获取报表代码中的参数值。我想根据传入参数的值使用User Function
.
这是我打开报告的控制器代码。如果我对买方变量进行硬编码,我会得到正确的图像以显示在图片框中:
public ActionResult PrintPoReport()
{
byte[] contents;
Telerik.Reporting.Processing.RenderingResult result;
using (var reportDocument = new LogisticsReports.Report1())
{
var buyerID = "999999"; //hard code buyerId for testing
var irs = new InstanceReportSource();
irs.ReportDocument = reportDocument;
irs.Parameters.Add(new Parameter("Buyer", "buyerID")); // parameter to determine which jpg will populate picture box. **Never gets to Report1**
Telerik.Reporting.Processing.ReportProcessor rp = new Telerik.Reporting.Processing.ReportProcessor();
result = rp.RenderReport("PDF", irs, null);
contents = result.DocumentBytes;
}
return File(contents, "application/pdf", "P0 #" + id + ".pdf");
}
报告背后的代码:
public partial class Report1 : Telerik.Reporting.Report
{
public Report1()
{
InitializeComponent();
var buyer = "999999"; //hard coded for testing...this works!
//Need to capture the passed in parameter here
if (buyer == "111111"){
this.pictureBox1.Value = "http://www.arctecalaska.com/images/signatures/111111.bmp";
}
if (buyer == "999999")
{
this.pictureBox1.Value = "http://www.arctecalaska.com/images/signatures/Ike.jpg";
}
}
}
}
问题是我从控制器发送的买家参数实际上从未进入报告。在调试期间,报告 InitializeComponent() 会在代码到达该行时立即运行:
var reportDocument = new LogisticsReports.Report1
我需要能够在报告呈现之前捕获和评估传入的参数,但我不知道该怎么做。有任何想法吗?