Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
148108 | Oct 6,2019 12:41 PM UTC | Oct 9,2019 06:39 AM UTC | Report Platform | 6 |
![]() |
Tags: Report Viewer |
export class AppComponent {
title = 'reportviewerapp';
public serviceUrl: string;
public reportPath: string;
public parameters: any;
constructor() {
this.serviceUrl = 'http://localhost:53800/api/Home';
this.reportPath = '/ReportData/Region.rdlc';
this.parameters = [{
name: 'CustomerID',
labels: ['InvoiceID'],
values: [10250],
nullable: false
}];
}
}
|
public partial class HomeController : Controller, IReportController
{
private IMemoryCache _cache;
private IHostingEnvironment _hostingEnvironment;
private Dictionary<string, object> jsonArray;
public HomeController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)
{
_cache = memoryCache;
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
public object PostReportAction([FromBody] Dictionary<string, object> jsonResult)
{
jsonArray = jsonResult;
return ReportHelper.ProcessReport(jsonResult, this, this._cache);
}
[ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(ReportResource resource)
{
return ReportHelper.GetResource(resource, this, _cache);
}
[HttpPost]
public object PostFormReportAction()
{
return ReportHelper.ProcessReport(null, this, this._cache);
}
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
string basePath = _hostingEnvironment.WebRootPath;
FileStream inputStream = new FileStream(basePath + reportOption.ReportModel.ReportPath, FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = inputStream;
reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
}
public void OnReportLoaded(ReportViewerOptions reportOption)
{
var parameters = ReportHelper.GetParameters(jsonArray, this, _cache);
if (parameters != null && parameters.Count > 0)
{
reportOption.ReportModel.DataSources.Clear();
reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData(Convert.ToInt32(parameters[0].Values[0])) });
}
}
} |
So, this is my fault for not specifying, but I am using the MVC control and full .net framework. I'm assuming the example holds mostly true for that as well, but are there any differences I should be aware of? Also what are you using as your caching source? Also, OnReportLoaded doesn't fire when clicking on View Report after hitting the filters.
public object PostReportAction(Dictionary<string, object> jsonResult)
{
if (jsonResult.TryGetValue("parameters", out var parameters)
&& parameters != null && !string.IsNullOrWhiteSpace(parameters.ToString()))
{
var parms = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Syncfusion.Reporting.Web.ReportParameter>>(parameters.ToString());
var param = parms.FirstOrDefault(i => i.Name == "ReportParameter1");
if (param != null)
{
var value = param.Values.FirstOrDefault();
if (!string.IsNullOrWhiteSpace(value))
{
var reportData = ProductList.GetData(value);
List<ReportDataSourceExt> extensionDataSources = new List<ReportDataSourceExt>() { new ReportDataSourceExt() { name = "list", value = reportData } };
jsonResult["dataSources"] = Newtonsoft.Json.JsonConvert.SerializeObject(extensionDataSources);
jsonResult["dataRefresh"] = true;
}
}
}
return ReportHelper.ProcessReport(jsonResult, this);
}
public class ReportDataSourceExt
{
public string name { get; set; }
public object value { get; set; }
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.