我是 C# 新手,我正在开发一个 asp.netcore 3.1 项目。我使用 AspNetCore.Reporting 库生成报告,它适用于其中一个,但对于多个则不起作用。我搜索了论坛,发现这是一个缓存问题,但我不知道如何解决它。有人可以帮我吗?
string path = "";
string mimtype = "";
int extension = 1;
Dictionary<string, string> parameters = new Dictionary<string, string>();
if (rpt== 1)
{
path = $"{this._env.WebRootPath}\\Reports\\Report1.rdlc";
parameters = g.GetAll();
}
if (rpt== 2)
{
path = $"{this._env.WebRootPath}\\Reports\\Report2.rdlc";
parameters = g.GetAll2();
}
if (rpt== 3)
{
path = $"{this._env.WebRootPath}\\Reports\\Report3.rdlc";
parameters = g.etatFinAutres(_context.Balance.ToList());
}
LocalReport localReport = new LocalReport(path);
var result = localReport.Execute(RenderType.Pdf, extension, parameters, mimtype);
return File(result.MainStream, "application/pdf");
这是AspNetCore.Reporting库的限制以及我在本期中所做的,在尝试不同的解决方案后,我完全迁移到ReportViewerCore.NETCoreNuget包库。 使用这个库,我们可以轻松生成报告,它是一个经常更新的包,具有多个先前版本。 (参考这个:https://www.nuget.org/packages/ReportViewerCore.NETCore/)
因此,请检查是否使用新包更新了您的代码。
Dictionary<string, string> parameters = new Dictionary<string, string>();
if (rpt== 1)
{
path = $"{this._env.WebRootPath}\\Reports\\Report1.rdlc";
parameters = g.GetAll();
}
if (rpt== 2)
{
path = $"{this._env.WebRootPath}\\Reports\\Report2.rdlc";
parameters = g.GetAll2();
}
if (rpt== 3)
{
path = $"{this._env.WebRootPath}\\Reports\\Report3.rdlc";
parameters = g.etatFinAutres(_context.Balance.ToList());
}
LocalReport localReport = new LocalReport();
localReport.ReportPath = path;
localReport.SetParameters(new[] { new ReportParameter("Parameter1", "parameters") });
byte[] pdfResult = localReport.Render("PDF");
localReport.Refresh();
return new FileContentResult(pdfResult, "application/pdf");
我希望这会有所帮助。