[Route("api/[controller]")]
[ApiController]
[EnableCors("MyPolicy")]
public class ReportApiController : ControllerBase, Syncfusion.EJ.ReportViewer.IReportController
{
// Report viewer requires a memory cache to store the information of consecutive client request and
// have the rendered report viewer information in server.
private Microsoft.Extensions.Caching.Memory.IMemoryCache _cache;
// IHostingEnvironment used with sample to get the application data from wwwroot.
private Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
Dictionary jsonArrayy;
// Post action to process the report from server based json parameters and send the result back to the client.
public ReportApiController(Microsoft.Extensions.Caching.Memory.IMemoryCache memoryCache,
Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
{
_cache = memoryCache;
_hostingEnvironment = hostingEnvironment;
}
// Post action to process the report from server based json parameters and send the result back to the client.
//[HttpPost]
[HttpPost("PostReportAction")]
public object PostReportAction([FromBody] Dictionary jsonArray)
{
this.jsonArrayy = jsonArray;
return Syncfusion.EJ.ReportViewer.ReportHelper.ProcessReport(jsonArray, this, this._cache);
}
public object PostFormReportAction()
{
return Syncfusion.EJ.ReportViewer.ReportHelper.ProcessReport(this.jsonArrayy, this, this._cache);
}
// Method will be called to initialize the report information to load the report with ReportHelper for processing.
public void OnInitReportOptions(Syncfusion.EJ.ReportViewer.ReportViewerOptions reportOption)
{
//reportOption.ReportModel.ReportingServer = new ReportingServerExt();
reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
//reportOption.ReportModel.ReportServerCredential = new System.Net.NetworkCredential("sbna", "war");
//reportOption.ReportModel.DataSourceCredentials.Add(new DataSourceCredentials("AdventureWorks", "ssrs1", "RDLReport1"));
string basePath = _hostingEnvironment.WebRootPath;
//// Here, we have loaded the sample report report from application the folder wwwroot. Sample.rdl should be there in wwwroot application folder.
FileStream reportStream = new FileStream(basePath + @"\Report1.rdlc", FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = reportStream;
}
// Method will be called when reported is loaded with internally to start to layout process with ReportHelper.
public void OnReportLoaded(Syncfusion.EJ.ReportViewer.ReportViewerOptions reportOption)
{
}
//Get action for getting resources from the report
[ActionName("GetResource")]
[AcceptVerbs("GET")]
// Method will be called from Report Viewer client to get the image src for Image report item.
public object GetResource(Syncfusion.EJ.ReportViewer.ReportResource resource)
{
return Syncfusion.EJ.ReportViewer.ReportHelper.GetResource(resource, this, _cache);
}
}