@page
@model IndexModel
@{
@ViewData["heading"];
}
<style>
body, html, #reportviewer {
overflow: hidden !important;
height: 100%;
width: 100%;
}
</style>
<ej-report-viewer id="reportviewer1" report-service-url="../ReportApi" processing-mode="Remote" />
<ej-script-manager></ej-script-manager>
|
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ReportViewerCore.Pages
{
public class IndexModel : PageModel
{
public void OnGet()
{
ViewData["heading"] = "ReportViewer Sample";
}
}
}
|
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Syncfusion.EJ.ReportViewer;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace ReportViewerCore.API
{
public partial class ReportApiController : Controller, IReportController
{
private IMemoryCache _cache;
private IHostingEnvironment _hostingEnvironment;
public ReportApiController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)
{
_cache = memoryCache;
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
public object PostReportAction([FromBody] Dictionary<string, object> 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 reportStream = new FileStream(basePath + @"\ReportRDL\GroupingAgg.rdl", FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = reportStream;
}
public void OnReportLoaded(ReportViewerOptions reportOption)
{
}
}
}
|
Index.cshtml |
Startup.cs |
<ej-report-viewer id="reportviewer1" report-service-url="../ReportApi" processing-mode="Remote" /> |
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
}); |
Index.cshtml |
Startup.cs |
<ej-report-viewer id="reportviewer1" report-service-url="../API/ReportApi" processing-mode="Remote" /> |
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "API/{controller}/{action=Index}/{id?}");
}); |
Index.cshtml |
Startup.cs |
<ej-report-viewer id="reportviewer1" report-service-url="../API/ReportApi" processing-mode="Remote" /> |
public partial class ReportApiController : Controller, IReportController
{
...... } |
<div style="height: 525px;width: 100%;">
<ej-report-viewer id="reportviewer1" report-service-url="../Home" processing-mode="Local" rendering-begin="renderingBegin" ajax-before-load="ajaxBeforeLoad" />
</div>
<script type="text/javascript">
function ajaxBeforeLoad(event) {
var parameters = [{
name: 'CustomerID',
labels: ['29889'],
values: [29889],
nullable: false
}];
event.data = parameters;
};
</script>
<ej-script-manager></ej-script-manager> |
public partial class HomeController : Controller, IReportController
{
private IMemoryCache _cache;
private IHostingEnvironment _hostingEnvironment;
public string DefaultParam = null;
public HomeController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)
{
_cache = memoryCache;
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
public object PostReportAction([FromBody] Dictionary<string, object> jsonResult)
{
if (jsonResult.ContainsKey("CustomData"))
{
DefaultParam = jsonResult["CustomData"].ToString();
}
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 + @"\ReportsTemplate\Region.rdlc", FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = inputStream;
}
public void OnReportLoaded(ReportViewerOptions reportOption)
{
var parameters = new List<ReportParameter>();
if (DefaultParam != null)
{
parameters = JsonConvert.DeserializeObject<List<ReportParameter>>(DefaultParam);
}
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])) });
}
}
} |
<ej-report-viewer id="reportviewer1" report-service-url="../ReportApi" processing-mode="Remote" ajax-before-load="ajaxBeforeLoad" />
<script type="text/javascript">
var parameters = [];
params = getParameters();
for (var i = 0; i < params.length; i++) {
parameters.push({ name: params[i].name, labels: [params[i].value], values: [params[i].value], nullable: "false" });// pass the parameter values
}
function getParameters() {
var parameters = window.location.search.substr(1);//get the parameter values from url
var listParams = [];
if (parameters != "") {
var splitValues = parameters.split("&");
for (var i = 0; i < splitValues.length; i++) {
var tempValue = splitValues[i].split("=");
listParams.push({ name: tempValue[0], value: tempValue[1] });// sepearte the name and value of the parameter
}
}
return listParams;
}
function ajaxBeforeLoad(event) {
event.model.parameters = parameters;
};
</script>
<ej-script-manager></ej-script-manager> |
Hi Rob,
We have checked the mentioned problem with your shared file but the sample is working properly with getting the Parameter from URL. So can you please confirm the below attached sample is working or not at your end.Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/ReportViewerCore-1814606191.
Note: Please use the below url’s examples for rendering the report in above shared sample.
If the issue is still persists then can you please revert the above sample with issue reproducible case and also please share the video for this issue to validate the mentioned problem at our end.
Regards,Mahendran S.
Query |
Response |
1) How to dynamically change report parameters using inputs in page and refresh the report viewer dynamically on input changes? |
We can able to dynamically change the report parameter. Please find the below KB documentation for how to dynamically change the parameters at client side.
|
2) In your example, there are breakpoints in the Javascript code in the Index.cshtml file. If they work for you, please tell me how you achieved it. For me, these breakpoints do not work in Visual Studio 2017.
|
We need to enable script debugging in VS 2017. Please find the below steps for how to enable the script debugging.
Step 1:Click the Tools tab and click the option button as shown in below snap.
Step 2: In Options window open the Debugging section and Enable the Script debugging as shown in below snap.
|