我正在使用RDLC文件呈现报告(没有SQL Server Reporting Services)并将其作为文件从我的控制器返回。这是我的MVC Web应用程序的一部分。
public ActionResult Index()
{
var report = new LocalReport();
report.ReportPath = Path.Combine(Server.MapPath("~/Reports"), "Report1.rdlc");
var reportData = new List<MonthlyData> {
new MonthlyData {RecordNo=1, Tid="123456", Active=10, Inactive=1}
};
ReportDataSource rd = new ReportDataSource("DataSet1", reportData);
report.DataSources.Add(rd);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + "PDF" + "</OutputFormat>" +
//" <PageWidth>8.5in</PageWidth>" +
//" <PageHeight>11in</PageHeight>" +
//" <MagroupinTop>0.5in</MagroupinTop>" +
//" <MagroupinLeft>1in</MagroupinLeft>" +
//" <MagroupinRight>1in</MagroupinRight>" +
//" <MagroupinBottom>0.5in</MagroupinBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = report.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
}
结果如下:
在我决定添加图表之前,一切都像魅力一样。
现在当我渲染它时,我有两个例外:
Microsoft.Reporting.WebForms.LocalProcessingException: „An error occurred during local report processing.”
DefinitionInvalidException: The definition of the report 'C:\Users\agutowski\Documents\Visual Studio 2017\Projects\rdlcMvc\rdlcMvc\Reports\Report1.rdlc' is invalid.
和
Microsoft.Reporting.WebForms.LocalProcessingException: „An error occurred during local report processing.”
ReportProcessingException: The definition of this report is not valid or supported by this version of Reporting Services. The report definition may have been created with a later version of Reporting Services, or contain content that is not well-formed or not valid based on Reporting Services schemas. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition' which cannot be upgraded.
我已经尝试过不同版本的Microsoft.ReportViewer.Common和Microsoft.ReportViewer.WebForms。
答案 0 :(得分:1)
我使用Microsoft.ReportingServices.ReportViewerControl.WebForms
和Microsoft.SqlServer.Types
NuGet包而不是Microsoft.ReportViewer.Common
和Microsoft.ReportViewer.WebForms
解决了这个问题。