Handling SSRS Report in ASP.Net MVC 3 using Microsoft Visual Studio 2010 RRS feed

  • Question

  • User-1153310292 posted

    hi there, i have a project using ASP.Net MVC 3. and for the report using SQL Server Reporting Service (a lot of rdl files). now i want to make report menu in my project. i want to add all those rdl file into my project ( i dont want to design the report again in my Project). is there any way to handling SSRS Report in MVC 3 without design the report again ? can someone give example code ?


    Monday, October 10, 2011 9:58 PM


All replies

  • User1918766559 posted

     the ReportViewer control won't work if you place it in an MVC view, since it requires ViewState. You'll have to create an old-school web form and put the ReportViewer there instead.

    A solution I used in a project I worked on was to create a custom route handler, so I could still make use of URL routing. The route handler would take parameters like the report name from the RouteData collection, create an instance of my web form, and pass the parameters to it via public properties. The web form would read these in Page_Load and configure the ReportViewer control.

    // Configure a route in Global.asax.cs that is handled by a ReportRouteHandler
    .Add("ReportRoute", new Route("Reports/{reportName}",
    new ReportRouteHandler());

    public class ReportRouteHandler : IRouteHandler {
    public IHttpHandler GetHttpHandler(RequestContext requestContext) {
    var reportName = requestContext.RouteData.Values["reportName"] as string;

    var webform = BuildManager
    typeof(Page)) as ReportViewerWebForm;
    .ReportToShow = reportName;
    return webform;

    This code is just a starting point if you decide to use this approach, of course. The one I created also did some user authentication and parameter validation before returning. 

    Details: http://stackoverflow.com/questions/4137835/viewing-ssrs-reports-in-an-asp-net-mvc-site  








    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 11, 2011 3:24 AM
  • User-1153310292 posted

    thank you anindita for your reply, now i want to make my report viewer first, if i have a problem when i make route, i will ask you.

    Wednesday, October 12, 2011 3:21 AM
  • User-1665555424 posted

    You will not only have to use an asp.net page but

      If using the Entity Framework or LinqToSql (if using partial classes) move the data into a separate project, the reportviewer cannot see the classes.

      Move the reports to another project/dll, VS10 has bugs were asp.net projects cannot see object datasources in web apps.  Then stream the reports from the dll in your mvc project.

    This applies for mvc and webform projects.  Using sql reports in the local mode is not a pleasent development experience.  Also watch your webserver memory if exporting large reports.   The reportviewer/export is very poorly designed.

    Tuesday, December 13, 2011 12:54 PM