0

Is there any better way to integrate rdlc report on mvc 5 asp.net. everyone is showing using iframe. but i don't like that solution.

Is there any elegant solution ??

Jake
  • 103
  • 6
  • what about save it and window.open javascript it – roy.d Jun 18 '17 at 12:34
  • Use `@Html.Partial` to render partial view containing ReportViewer control, see this post for details (applicable for Razor view in MVC 5 too): https://stackoverflow.com/questions/6144513/how-can-i-use-a-reportviewer-control-in-an-asp-net-mvc-3-razor-view. – Tetsuya Yamamoto Jun 19 '17 at 03:38

1 Answers1

0

How about rendering your rdlc report in a separate tab ?!

For instance,:

In your controller:

 public ActionResult Report()
        {
            LocalReport localReport = new LocalReport();
            localReport.ReportPath = Server.MapPath("~/Reports/Report1.rdlc");

            // you may comment dbContext if the report is static or needs no DB-connection
            using (dbContext db = new dbContext())
            {
                ReportDataSource ds1 = new ReportDataSource("DataSet_Header", db.table_X.ToList());
                ReportDataSource ds2 = new ReportDataSource("DataSet_Detail", db.StoreedProcedure_X(5).ToList());
                // ...


                localReport.DataSources.Add(ds1);
                localReport.DataSources.Add(ds2);


                string mimeType;
                string encoding;
                string fileNameExtension;
                Warning[] warnings;
                string[] streams;
                string reportType = "PDF";
                string deviceInfo = "<DeviceInfo>" +
                    "<OutputFormat>PDF</OutputFormat>"+
                    "<PageWidth>11.69in</PageWidth>"+
                    "<PageHeight>8.27in</PageHeight>"+
                    "</DeviceInfo>";
                byte[] renderBytes;


               // add report parameters here, if any
               Microsoft.Reporting.WebForms.ReportParameter[] para = new ReportParameter[] {
                    new ReportParameter("sample", Sample.ToString())
                // , add more parameters if anymore exists ...
                };


                localReport.SetParameters(para);

                renderBytes = localReport.Render(
                    reportType,
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings
                    );

                return File(renderBytes, "application/pdf");
            } // end using
        }


In Your View:

You can create <a> tag or @Html.ActionLink to the above action method:

<a href="@Url.Action("Report", "controllerName")">PRINT</a>

Hope this helped :)

A. Nadjar
  • 2,440
  • 2
  • 19
  • 20