11.1 Feature Days (from TechEd) – New ASP.NET MVC Reporting Extensions

Update: Available now for download are the DevExpress ASP.NET MVC Reporting Extensions. See a live online demo here: http://dxpr.es/kQ94or

For our third day here at TechEd, I thought I would show you the new ASP.NET MVC reporting extensions coming in our v2011.1 release. These include a report viewer extension as well as a report toolbar extension.

There are a couple of things to keep in mind when using these extensions. The first is how you decided to pass the report from the controller to the view. In ASP.NET MVC you can use any of the traditional models available: whether it be passed to the View through the model or the ViewData dictionary exposed to the View. Here is an example of the former:

  1: public ActionResult Index()
  2: {
  3:     ViewBag.Message = "Welcome to DevExpress Extensions for ASP.NET MVC!";
  4:     return View(new ProductReport());
  5: }

The next thing to keep in mind is how the ReportViewer extension actually works (in conjunction with the report toolbar extension). Since the report viewer uses asynchronous requests to the server in order to refresh its content, the report viewer extension is best used when exposed in its own partial view. The following snippet shows the partial view markup/code used to generate the viewer. Notice that the Model property inside of the partial view corresponds to the model passed to the View from the Index controller method above.

  1: @Html.DevExpress().ReportViewer(settings =>
  2: {
  3:     settings.Name = "reportViewer";
  4:     settings.Report = (DevExpress.XtraReports.UI.XtraReport)Model;
  5:     settings.CallbackRouteValues = new { Controller = "Home", Action = "ReportViewerPartial" };
  6:     settings.ExportRouteValues = new { Controller = "Home", Action = "ReportViewerExportTo" };
  7: }).GetHtml()

The first two settings above are pretty self explanatory: they define the name of the control along with the report source (in this case the actual Model property in the View). The second two have to do primarily with how the report viewer interacts with the controller to refresh itself. The CallBackRouteValuse setting deals primarily with refreshing elements within the report as it is displayed while the ExportRouteValues deal primarily with the task of exporting the actual report. The following code snippet highlights this distinction:

  1: public ActionResult ReportViewerPartial()
  2: {
  3:     return PartialView("_reportViewer", new ProductReport());
  4: }
  5: 
  6: public ActionResult ReportViewerExportTo()
  7: {
  8:     return ReportViewerExtension.ExportTo(new ProductReport());
  9: }

Notice on line 3 in the snippet above that the controller actually returns the partial view entitled “_reportViewer” that contains the report viewer extension as shown above.

The last portion is to actually create a view that consumes the report viewers partial and adds the toolbar functionality:

  1: @{
  2:     ViewBag.Title = "Home Page";
  3: }
  4: 
  5: <div class="title">@ViewBag.Message</div>
  6: <div id="report">
  7:     @Html.DevExpress().ReportToolbar(settings =>
  8:        {
  9:            settings.Name = "toolbar1";
 10:            settings.ReportViewerName = "reportViewer";
 11:        }).GetHtml()
 12: 
 13:     @Html.Partial("_reportViewer")
 14: </div>

The only significant snippet to consider here is found on line 10. It corresponds the the actual name of the report viewer that is being rendered.

Here is the example from above fully rendered (elided bottom portion for brevity):

mvc

This is indeed great news for those of us who use MVC heavily.

As always, if there are any comments and/or questions, feel free to get a hold of me!

Seth Juarez
Email: sethj@devexpress.com
Twitter: @SethJuarez

DXperience? What's That?

DXperience is the .NET developer's secret weapon. Get full access to a complete suite of professional components that let you instantly drop in new features, designer styles and fast performance for your applications. Try a fully-functional version of DXperience for free now: http://www.devexpress.com/Downloads/NET/

6 comment(s)
Nick Olsen

Will the MVC reports have drill down capability?  Do you have an estimated release date for v2011.1?

19 May, 2011
Julian Bucknall (DevExpress)

Nicholas: We released the first beta of DXperience this morning. That means we're on the countdown to the actual release. As to how quickly, well it does depend on feedback from our customers and so on.

Cheers, Julian

19 May, 2011
Alberto Payero Mota

Other things, this only work with asp.net mvc 3 or work with Asp.net MVC 2 too?.

Plase try to expose example in vb.net too!

thanks!.

2 June, 2011
Faik Garibovic

Great stuff!

I am new to ASP.MVC, just finishing my first real project in it and I really like it. With that said, any new extensions are more then welcome.

With reports solved, I'd say we only need you guys to port your DataView and News over to MVC. Everything you have so far plus those would make it possible to migrate any web app we made so far to MVC.

Keep up the good work. Cheers!

3 June, 2011
Alberto Payero Mota

Mr., can you tell me when you will release the new version with ASP.NET MVC Reporting Extensions?.

and I want to mak a test!

8 June, 2011
Christian Andersen

Is something like this going to show up for the Scheduler control as well?

29 September, 2011

Please login or register to post comments.