Integrating ActiveReports into ASP.NET MVC

A long time favorite PDF reporting tool of mine is ActiveReports for .NET.  It's relatively painless to integrate into your project, has a great designer tool, and has plenty of power for more advanced reporting needs. When I started becoming an ASP.NET MVC zealot, I was afraid of losing the ability to use this great tool.  With a little tinkering, I got it to play nicely within an MVC project and have included the steps below for future reference:

  1. The first step is to add ActiveReports to your project as you normally would.  This includes updating your web.config following the installation guidelines such as adding the ActiveReports handlers to the HttpHanders section and adding the appropriate assembly references.
  2. The next step is getting the MVC framework to ignore calls to any ActiveReport reports.  To do this, we need to ignore a couple of routes in your routing configuration as follows:
    routes.IgnoreRoute ( "{*allActiveReportRpxHandler}", 
        new { allActiveReportRpxHandler = @".*\.rpx(/.*)?" } );
    routes.IgnoreRoute ( "{*allActiveReport}", 
        new { allActiveReport = @".*\.ActiveReport(/.*)?" } );
    routes.IgnoreRoute ( "{*allArCacheItem}", 
        new { allArCacheItem = @".*\.ArCacheItem(/.*)?" } );
  3. Add your ActiveReports as you normally would to your project.
  4. Finally, and this is the important bit, you cannot use the ActiveReports web viewer in the MVC environment because it assumes use of the ASP.NET page lifecycle.  Accordingly, I haven't found a way to render the generated PDF directly to the web page without first saving it somewhere on the file system.  So I've taken to streaming the PDF to the client when they request a report.  Here's an example action method within a controller which does this using MvcContrib's BinaryResult (you could also use MVC's native BinaryResult):
    public ActionResult GenerateMyActiveReport() {
        MyActiveReport3Class myReport = 
            new MyActiveReport3Class(someViewModelOrServiceDependency);
        myReport.Run();
    
        MemoryStream reportStream = new MemoryStream();
        new DataDynamics.ActiveReports.Export.Pdf.PdfExport()
            .Export(myReport.Document, reportStream);
    
        return new BinaryResult(reportStream.GetBuffer(), 
            "application/pdf", true, "SomeCoolReport.pdf");
    }

And that's it.  A couple of little tweaks to the normal procedures and we have ActiveReports support within our ASP.NET MVC project.

Billy McCafferty


Posted 05-11-2009 1:33 PM by Billy McCafferty
Filed under: ,

[Advertisement]

Comments

DotNetShoutout wrote Integrating ActiveReports into ASP.NET MVC - Billy McCafferty - Devlicio.us
on 05-12-2009 4:37 AM

Thank you for submitting this cool story - Trackback from DotNetShoutout

Aaron Palmer wrote re: Integrating ActiveReports into ASP.NET MVC
on 05-12-2009 8:42 AM

First time I've ever commented on your blog, but I do read it fairly regularly.  I thought I'd note a question I asked on stackoverflow a while back.

stackoverflow.com/.../how-to-render-active-reports-webviewer-in-asp-net-mvc

Side note... when is #arch going to be finalized for the asp.net mvc rtm?

Tommy Kelly wrote re: Integrating ActiveReports into ASP.NET MVC
on 05-12-2009 11:49 AM

ActiveReports for .NET is awesome because its so flexible.  You have it right by rendering the report to PDF and then pushing it to the user.  If you do it that way, you don't have to add any of those IgnoreRoute statements because that is for the WebViewer control (which I would suggest not using).  The next version of Active Reports will have a flash viewer, which hopefully will solve the problems with the WebViewer control. Plus, its the coolest place to work at (former employee)!

Billy McCafferty wrote re: Integrating ActiveReports into ASP.NET MVC
on 05-15-2009 4:06 PM

@Aaron, soon! ;)  I'm launching itsamuraischool.com this weekend and then will be turning attention back to S#arp Architecture 1.0.

@Tommy, thanks for the info about the flash viewer...I look forward to using it.

Murph wrote re: Integrating ActiveReports into ASP.NET MVC
on 06-25-2009 5:26 PM

Any way to export an MVC/ActiveReports report, i.e. pdf, xml, etc? I need to do reporting in our MVC app and was used ActiveReports a few years ago--great then, too!  If it cannot export the report, does anyone have suggestions for reporting in MVC with export capability?

Thanks, Murph

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)