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

how to set reportOption.ReportModel.Stream = inputStream; from view in mvc

I'm using ASP Core MVC
In my controller I set the location of the rdl in

        public void OnInitReportOptions(ReportViewerOptions reportOption)
        {
            string basePath = _hostingEnvironment.WebRootPath;
            FileStream inputStream = new FileStream(basePath + @"\Report.rdl", FileMode.Open, FileAccess.Read);
            reportOption.ReportModel.Stream = inputStream;

        }

The only thing that will change for each report is the rdl name, so if possible I'd like to use the same controller for every report instead of recreating essentially the same Controller over and over along with the associated View folders. Is it possible to either set the report file name in the view ej-report-viewer tag or maybe reportOptions has some sort of UDF I can set to Report.rdl? Although I'm open to any other sort of work around like a Case or IF statement inside OnInitReportOptions.

1 Reply

MM Mageshyadav M Syncfusion Team April 11, 2019 08:07 AM

Hi Justin, 
 
We can able to change the report path and render the report in same controller. We have prepared the simple sample with drop down list to change the report dynamically when using the setModel method in client side and it can be downloaded from below location.  
 
Please find the below code example for how to change the reports using setModel method in client side.  
Index.cshtml  
@using Syncfusion.JavaScript  
@{  
    ViewData["Title"] = "Syncfusion ReportViewer control";  
}  
<select id="dropdown1">  
    <option value="GroupingAgg">GroupingAgg</option>  
    <option value="Sales Order Detail">Sales Order Detail</option>  
</select>  
  
<div style="align-items:flex-start; height:100px;width:100px">  
    <ej-drop-down-list id="dropdown1" selected-item-index="0" change="onChange"></ej-drop-down-list>  
</div>  
<div style=" align-items:center; height:525px;width: 100%;">  
    <ej-report-viewer id="reportviewer1" report-service-url="../Home" report-path="/ReportsTemplate/GroupingAgg.rdl"processing-mode="Remote" />  
</div>  
  
<script type="text/javascript">  
  
        function onChange(args) {  
            reportpath = "/ReportsTemplate/" + args.selectedValue + ".rdl";  
            var reportObject = $("#reportviewer1").data("ejReportViewer");  
            reportObject.setModel({  
                reportPath: reportpath  
    });  
}  
</script>  
  
<ej-script-manager></ej-script-manager>  
 
Please find the below code example for how to pass that report path to get the stream in controller side.  
HomeController.cs  
        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;  
        }  
 
Regards, 
Mageshyadav.M 


Loader.
Live Chat Icon For mobile
Up arrow icon