We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Starting in 2019, the Reporting control is no longer included in Essential Studio. If you're experiencing issues with the Syncfusion Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion and appreciate your understanding.

Parameters for local processing

Hi,

I have a reportviewer that is processing report locally. 

<ej-report-viewer id="reportviewer1" enable-page-cache="false" report-path="obracun.rdl" report-service-url="http://localhost:5002/Report" processing-mode="Local" />

 public void OnReportLoaded(ReportViewerOptions reportOption)
{
     reportOption.ReportModel.DataSources.Clear();

     var parameters = reportOption.ReportModel.Parameters;

     var obracun = new Syncfusion.Report.ReportDataSource
            {
                Name = "Obracun",
                Value = GetData(parameters )
            };
}

And that is working fine.

But what I was unable to get is report parameters from report options: reportOption.ReportModel.Parameters, it is always null.

Use case is that I need to filter data before returning ReportDataSource. 

Is there any way to define parameters on front-end (ej-report-viewer). From ViewData/ViewBag somehow so that it would pass me a parameter to OnInitReportOptions/OnReportLoaded ?

Thanks

2 Replies

MS Mahendran Shanmugam Syncfusion Team November 13, 2018 10:20 AM UTC

Hi Vedran, 

Thanks for your interest in our Syncfusion products. 

We can to get the report parameter values using “ajaxBeforeLoad” event in reportloaded method at controller side. We have prepared a simple sample to load the RDLC report by passing the parameter from client to Report Controller as shown in below code example.  

Index.html 
<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> 

HomeController.cs 
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])) }); 
            } 
        } 
    } 

We have prepared a sample to get the report parameter from client side to controller side and it can be downloaded from below location. 

Regards, 
Mahendran S. 



VV Vedran Vukasovic November 15, 2018 07:38 AM UTC

Hi,

thx, this is working.

Loader.
Live Chat Icon For mobile
Up arrow icon