No, the ReportViewer control will not work if you place it in the MVC view because it requires a ViewState. You will need to create an old school web form and put ReportViewer instead.
The solution I used in the project I was working on was to create a custom route handler, so I could still use URL routing. The route handler accepts parameters such as the name of the report from the RouteData collection, creates an instance of my web form and passes the parameters to it through public properties. The web form will read them in Page_Load and configure the ReportViewer control.
// Configure a route in Global.asax.cs that is handled by a ReportRouteHandler routes.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 .CreateInstanceFromVirtualPath("~/Path/To/ReportViewerWebForm.aspx", typeof(Page)) as ReportViewerWebForm; webform.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 performed some user authentication and parameter checking before returning.
Refresh . It looks like if you are using ASP.NET 4.0, most of this can be done automatically
Brant Bobby Nov 09 '10 at 20:32 2010-11-09 20:32
source share