Вы можете создать страницу ASPX с отчетом, а затем встроить отчет в <iframe />
на ваш взгляд MVC, или вы можете попробовать с помощью этого метода, который возвращает пар непосредственно на ответ:
private void RenderReport() {
LocalReport localReport = new LocalReport();
localReport.ReportPath = Server.MapPath("~/YourReportName.rdlc");
// Add your data source
ReportDataSource reportDataSource = new ReportDataSource("YourCollection", yourCollection);
localReport.DataSources.Add(reportDataSource);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
//The DeviceInfo settings should be changed based on the reportType
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>1in</MarginLeft>" +
" <MarginRight>1in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//Render
renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Write to the outputstream
//Set content-disposition to "attachment" so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
}
вы, возможно, потребуется изменить ReportType к WATH вам нужно, и не забудьте изменить DeviceInfo соответственно к нему. Вы можете найти информацию here.
Надеюсь, это поможет вам.
Есть ли какие-либо варианты там кроме PDF. Я дал MHTML, но это была ошибка: «Формат параметра - исключение вне диапазона». – Tanya