Display SSRS report in ASP .NET MVC site

If you are required to display a SSRS (Sql Server Report Services) report from a report server as a standalone page within your site application then the best solution will be to create a plain old web form page with the ReportViewer control. The ReportViewer control you can find in Microsoft Report Viewer Redistributable Package which includes assemblies for Web as well as for Windows .NET applications.

The task becomes a little bit difficult when you want to display the report as a part of another page, and in our case it is an MVC view rather than a web form.

You could create a standalone web form for this page only, but if your view has a hierarchy of master pages you have to double each master page for MVC and Web Form technology. It will violate dry principles of your UI markup and code behind. Make a wise consideration and review possible tradeoffs in this case.

Another approach is to use a frame with a source of the report located directly at the report server. At first it looks the easiest solution. But you may have a big disadvantage if the sites have a different authentication and authorization models, or would change them in future putting your users in frustration and confuse. You also need to consider all these pros and cons.

In my particular case I have come out with solution of creating a custom report renderer which returns a list of parameters, available formats, is able to set new values of the parameters and returns a stream data of the report. Therefore I can use this renderer in my controller and pass all these data via a model to a view. The renderer uses the ServerReport class under the curtains. The ServerReport is a composite part of the ReportViewer and is used to render report from a remote report server using SOAP.

These methods of the ServerReport were used :

  • GetParameters(), to get available parameters of a report
  • SetParameters(), to set new values for the parameters
  • ListRenderingExtensions(), to get all available extensions
  • Render(string format, string deviceInfo), to get bytes of the report in the particular format. The deviceInfo allows tuning of the report appearance using XML markup defined at Reporting Services Device Information Settings for each format (look at @msdn). This method has a lot of overloads by the way. Pick up the most suitable.

Some code snippets of this topic are at the Lukianol codeplex project under the namespace of the Lukianol.Web.Report.

Advertisements
This entry was posted in .NET, ASP .NET MVC, SSRS. Bookmark the permalink.

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