Reporting In ASP.NET MVC 3

This past week I had a need to create a report for an ASP.NET MVC 3 app I was working on. The requirement for the report was to show charts of the data and to provide the original data using databars and indicators and output it to PDF. Not a very complex report at all. But somehow, there were some Goldilocks moments which I present to you now.

Telerik.Reporting – Too Cold

The first thing I tried was the Telerik Reporting solution. It was easy to do but the charting gave me some headaches. The main pain point for me was that it did not support Radius charts and there were no plans to add it. The other problem was with the way the reporting control (server side control) had to be used. Its as if they created it for regular ASP.NET and then hacked it for MVC. See example code here.

image

Aspose.Cells – Too Hot

Then I tried Aspose.Cells to generate an excel sheet and perform the necessary conversion to PDF. This tool was simple to implement but very tedious to get looking just right. I didn’t have a lot of time to spend on the reporting aspect and It felt like I was writing VBA. To be clear, Excel is inherently tedious to work on and Aspose.Cells is the best implementation of Excel I have ever seen. Not even Microsoft has a good implementation that just works (especially in a server environment). The main issues I ran into with Aspose.Cells was that indicators were buggy and would not work properly. The other issue was saving as PDF. It would save fine but the indicators and databars would not print in the PDF report. We use Aspose.Cells in other projects where we need to generate reports that are mostly excel files to allow for data manipulation. It works there and its awesome. However, for this project, it was just not right. 

At this point we started looking at using HTML 5 to generate the charts and just spit the data out on the page. But then we had the issue of taking an HTML page and converting it to a PDF. There are some tools out there that will do it but its not something I wanted to do.

Product Diagram of Aspose.Cells for .NET

Report Builder 3.0 – Just Right

I finally tried Report Builder 3.0. The UI is not the easiest to work with when trying to do styling etc. but it got the job done in record time and the report exported to PDF nicely. It worked. Pleased with this result I was ready to use the LocalReport ability (‘Represents a report that is processed and rendered locally without connecting to a report server’) to render the report in the MVC Controller and stream the PDF file as a result of the Controller method.

The problem is that Microsoft in its infinite wisdom has not enabled that functionality for reports created in Report Builder 3.0.

imageimage

Why in the world would such a useful functionality be crippled on purpose? There must be a workaround!

Stackoveflow was checked but did not help. Changing the report type by modifying the xml does not render it useable. Then I came across this link which stated:

The reports that are created with ReportBuilder 3.0 use the RDL 2010 schema but the ReportViewer in local mode can only process/render reports that use the 2005 or 2008 schema. If you publish the 2010 report to a report server and use the ReportViewer in remote mode you can render the 2010 RDL Report.

So I had to find another way around this issue. I had to use a Report Server to host the report.

Then I could use the WebClient class to request the report via http. The URL I used was:

http://<SERVER_NAME>/ReportServer_SQLEXPRESS?%2fGAP%2f<REPORT_NAME>&rs:Command=Render&rs:Format=PDF&rc:Toolbar=false&rc:Parameters=false&<PARAM_1>=<VALUE&gt;

Notice that there are some things you have to replace in the URL above. Also note that ‘ReportServer_SQLEXPRESS’ is being used. This is because the instance is running off SQL Express and not the full blown SQL 2008 R2 which you should used in production. And that ‘Format=PDF’ will render the report as a PDF.

 

So, to conclude, Report Builder 3.0 was the easiest to use to build the report and generating the PDF from the report was also simple to accomplish. Report Builder supports many different styles of charts and data displays much like Excel. I’m now going to push Report Builder for all our reports considering the ease with which they can be modified and just how easy they are to use. I could put the data on the report and give it to the designer to prettify.

Also, in case you did not know this, Microsoft SQL Server2008 R2 RTM – Express with Advanced Services is a fully functioning SQL SERVER 2008 database with all the trimmings.

  • Same database engine as other versions of SQL Server.
  • Supports 10 GB of storage per database.
  • Backup and restore with ease.
  • Compatible with all editions of SQL Server and SQL Azure.
  • Designed to work with Visual Studio and ASP.NET.
  • Available with a graphical management tool.
  • Offers reporting capabilities, full-text search, and spatial support.
  • About these ads
    Tagged , , , , , , , , , , ,

    5 thoughts on “Reporting In ASP.NET MVC 3

    1. aaa says:

      Is it possible to save the results of a parametrized query to a dataset object and then assign the dataset as the reports source? The query is parametrized from an MsAccess Db so that it is not accessible via Report Builder. So saved the results of one query to a table and then used the table to create a report template. Now that a report template is available, how does one use a dataset containing the results from a parametrized query as the datasource for the report template?

    2. Sutikshan says:

      Hi , You mentioned that SO did not solve your problem.

      “Stackoveflow was checked but did not help. Changing the report type by modifying the xml does not render it useable. ”

      But in same SO thread, you answered your own question, that it is solved now :-

      Is your answer on SO, is more latest, and should we follow that?

      • aboutdev says:

        Hi Sutikshan.
        As you mentioned, I checked SO and specifically the question I linked to (“But in same SO thread, you answered your own question” — Note: I did not post that question or answer that question). Even though the answer was provided, it did not help me with my issue. That’s not to say that it may not help you. The only way to know would be to try. When I was working on this problem, the only way I could find to solve it was the approach I took. Perhaps there has been an update from MS since then but I haven’t looked at it in a while.
        Thanks.
        Aboutdev

    3. Vassil Petev says:

      Hi Aboutdev,
      Thank you for the honest review of Telerik Reporting. I wanted to let you know that as of last month we offer radius charts in Telerik Reporting (Q1 2013). We are also planning on introducing a new web viewer which will work in MVC 4 (note that we will still offer a server wrapper because Telerik Reporting is a server product). You can find more info on the new web viewer in the current roadmap: http://www.telerik.com/products/reporting/whats-new/roadmap.aspx.

      Thanks,
      Vassil Petev
      Product Manager

      • aboutdev says:

        Thank you Vassil. Having a server side control requires state and that was something I wanted to avoid in an MVC app. If Telerik build an HTML5 report generation tool that would be a great step forward. I look forward to seeing what your excellent team produces.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    Follow

    Get every new post delivered to your Inbox.

    %d bloggers like this: