Last week I released some code that I created for work to get rid of the ASP.NET WebForms reliance to use a Report Viewer control on your MVC website. Immediately after release, someone commented on my reddit article suggesting that I should see what it would take to enable this for .NET Core. I thought it would be a fun idea to gain some experience with .NET Core so I went for.
The other day, I released the code for the .NET Core portion of the project on the same Github repo and I wanted to share it and see if anyone else wants to try using it.
The way that my code works for viewing the reports is that I’m essentially redrawing the report viewer controls for paging / searching / exporting / printing using Bootstrap (which you don’t have to be tied to). Each button does an ajax call to the controller which has some predefined controller actions to deal with the report viewer features so that you don’t have to reinvent the wheel. The custom controller actions will call into your SSRS ReportExecutionService soap service to get information about the report.
There are sample projects in my codebase that are for the standard ASP.NET MVC Razor and for the .NET Core version of MVC.
- This project will work in standard MVC projects as well as .NET Core (there is a library for each).
- I have only tested this with SSRS Server Reports – since I’m contacting the SSRS ReportExecution asmx file I don’t believe that would work with local rdl files.
- I’m using the following libraries in my example projects currently
- JQuery v2.1.1
- Bootstrap v3.3.7
- Select2 v4.0.3
- JQuery Highlight v5 (this is optional and is used for the “Find” feature of the viewer).
How to Set it Up
- Install from NuGet packages
- Standard .NET Framework – https://www.nuget.org/packages/AlanJuden.MvcReportViewer/
- .NetCore – https://www.nuget.org/packages/AlanJuden.MvcReportViewer.NetCore/
- Or, download code from GitHub – https://github.com/alanjuden/MvcReportViewer
- Hopefully you already have a project created, if not…set one up.
- Determine the correct AlanJuden.MvcReportViewer library to use.
- .Net Core based project => AlanJuden.MvcReportViewer.NetCore
- ASP.NET MVC based project => AlanJuden.MvcReportViewer
- Compile the project you chose from step 3 or pull it into your project.
- In your project, you need to setup a ReportController (that’s what I’ve been calling it but you can call it whatever you want).
- On your ReportController, you’ll need to inherit from AlanJuden.MvcReportViewer.ReportController.
- Add the mvcreportviewer-bootstrap.css to your project.
- You’ll now need to setup a couple of properties that are expected by being abstracted on the base ReportController.
- This would be a good time to setup the credentials that you need to run as to have access on the report viewer.
- Setup a View Page for your Report Viewer, I have been calling mine “ReportViewer.cshtml” (this should live in your /Views/Report/ directory).
- You may need to edit the path to some of your script / css files.
- Start setting up your own reports on your controller.
- You’re all set…give it a try!
- Let me know what you think by hitting me up on the comments below, by my contact page, or any of the social sites I have listed on my site.
Prashanth BDecember 2, 2016 1:45 am
i am getting “The HTTP request was forbidden with client authentication scheme ‘Ntlm’.” exception when trying execute the code. Your help is much appreciated.