提问人:Kamal AlSabah 提问时间:6/4/2023 最后编辑:marc_sKamal AlSabah 更新时间:6/5/2023 访问量:92
如何解决将 ReportViewerCore.NETCore 15.1.17 与 ASP.NET Core rdlc 子报告一起使用时的“未找到子报告”错误?
How do I resolve 'subreport not found' error when using ReportViewerCore.NETCore 15.1.17 with ASP.NET Core rdlc subreport?
问:
当我在代码中使用它时,它会重新发出 pdf,但在位置子报告中返回错误。
错误:
在指定的出勤位置找不到子报告“出勤”。请核实子报告是否已发布,名称是否正确。
我的代码:
public async Task<FileContentResult> Attendance(InputFilterDto input)
{
var path = $"{this.host.WebRootPath}\\Reports\\attendanceForUser.rdlc";
Stream reportDefinition = new FileStream(path, FileMode.Open, FileAccess.Read);
LocalReport report = new LocalReport();
var datasourses = await Datasourses(input);
foreach (var item in datasourses.DataSources)
{
report.DataSources.Add(item);
}
report.LoadReportDefinition(reportDefinition);
report.SubreportProcessing += (sender, e) =>
{
foreach (var item in datasourses.DataSources)
{
e.DataSources.Add(item);
}
};
byte[] pdf = report.Render("PDF");
var fileResult = new FileContentResult(pdf, "application/pdf")
{
FileDownloadName = DateTime.Now.ToString("yy-MM-dd-hh-mm")
};
return fileResult;
}
我问了gpt聊天,但它没有帮助我解决问题
答:
0赞
Kamal AlSabah
6/5/2023
#1
使用此代码:
var path = $"{this.host.WebRootPath}\\Reports\\attendanceForUser.rdlc";
var subReportpath = $"{this.host.WebRootPath}\\Reports\\attendance.rdlc";
using (Stream reportDefinition = new FileStream(path, FileMode.Open, FileAccess.Read))
{
LocalReport report = new LocalReport();
var datasourses = await Datasourses(input);
report.LoadReportDefinition(reportDefinition);
using (Stream subReportDefinition = new FileStream(subReportpath, FileMode.Open, FileAccess.Read))
{
report.LoadSubreportDefinition("attendance", subReportDefinition);
}
foreach (var item in datasourses.DataSources)
{
report.DataSources.Add(item);
}
//report.SetParameters(parameters);
report.SubreportProcessing += (sender, e) =>
{
foreach (var item in datasourses.DataSources)
{
e.DataSources.Add(item);
}
};
byte[] pdf = report.Render("PDF");
var fileResult = new FileContentResult(pdf, "application/pdf")
{
FileDownloadName = DateTime.Now.ToString("yy-MM-dd-hh-mm")
};
return fileResult;
}
评论
0赞
Jeremy Caney
6/5/2023
请记住,Stack Overflow 不仅旨在解决眼前的问题,还旨在帮助未来的读者找到类似问题的解决方案,这需要了解底层代码。这对于我们社区中不熟悉语法的初学者来说尤其重要。鉴于此,您能否编辑您的答案以包括对您正在做的事情的解释以及您为什么认为这是最好的方法?
评论