I would like to render an RDLC report in HTML within an ASP.NET MVC project.
I successfully made a prototype that renders an RDLC report in PDF, Excel, and TIFF image, with the help of this article. But I was surprised that HTML is not one of the default available formats in LocalReport.Render()
.
I came across this article, which describes a trick to enable the rendering format of HTML4.0, but I think that is only for a ReportViewer
control (I could be wrong though).
The question is, in MVC how to render an RDLC report in HTML just like a ReportView
does (see the screenshot below)?
This is a simple task. You can follow the following steps.
Create a Class ReportData and add it to the Reports folder. Add the following code to the Class.
Add another Class and named it ReportBasePage.cs. Add the following code in this Class.
Add ScriptManager to the ReportView.aspx page. Now Take a Report Viewer to the page. In report viewer set the property AsyncRendering="false". The code is given below.
Add two NameSpace in ReportView.aspx.cs
Change the System.Web.UI.Page to ReportBasePage. Just replace your code using the following.
Add a Folder to the Reports Folder and named it Report. Now add a RDLC report to the Reports/Report folder and named it ClosingInventory.rdlc.
Now add a Controller and Named it ReportController. In to the controller add the following action method.
Add a view page click on the ReportViewer Controller. Named the view page ReportViewer.cshtml. Add the following code to the view page.
Add an Iframe. Set the property of the Iframe as follows
Add Following JavaScript to the viewer.
In Web.config file add the following key to the appSettings section add
In system.web handlers Section add the following key
add
verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Change your data source as your own. This solution is very simple and I think every one enjoy it.
You can use the ReportViewer object to render an RDLC to PDF or HTML. For my case (below) I wanted a PDF document and I returned it as a FileContentResult ActionResult. If you want it to return as a download use the File ActionResult (I've commented that out for your use).
I put this project together ages ago http://mvcrdlc.codeplex.com/
From memory there should be an html render of the rdlc as well as the PDF