xtrareports-115310-web-reporting-asp-net-mvc-reporting-asp-net-mvc-reporting-extension-integration.md
This topic explains how to incorporate DevExpress Reporting Extensions for ASP.NET MVC into existing ASP.NET MVC applications.
When you create a new ASP.NET MVC application using the Devexpress Template Gallery or use the general approach to integrate reporting extensions into an existing project, the resulting application is configured to support the whole set of DevExpress ASP.NET MVC extensions. This may be redundant for some applications, particularly if you want to only utilize the XtraReports Suite. In this case, perform the steps described below to incorporate DevExpress Reporting Extensions for ASP.NET MVC into your project.
You can install NuGet packages and have the references and settings configured automatically. As an alternative, you can reference the assemblies and register settings manually.
Right-click the References node in the Solution Explorer, select Manage NuGet Packages and install the following packages from the DevExpress NuGet Gallery:
After installation, all references and configuration settings are added automatically.
You do not have to add NuGet packages if you have DevExpress components installed on your machine. Add references to the following assembly files in the ASP.NET MVC application (refer to the Assemblies Deployed with ASP.NET MVC Reporting Applications document to learn more).
The DevExpress installer registers all assemblies in the GAC. You can open the Reference Manager dialog (for instance, using the PROJECT | Add Reference… menu item) and select these assemblies in the dialog’s Extensions tab.
Note
The version numbers and public key mentioned in this document may differ depending on the product version you purchased.
Set the CopyLocal property of the referenced assemblies to true or add the following lines to the ‘configuration > system.web > compilation > assemblies‘ section of the application’s Web.config file.
...
<assemblies>
...
<add assembly="DevExpress.Charts.v25.2.Core, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.CodeParser.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Data.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.DataAccess.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Office.v25.2.Core, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.PivotGrid.v25.2.Core, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Printing.v25.2.Core, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.RichEdit.v25.2.Core, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Sparkline.v25.2.Core, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.ASPxThemes.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.Mvc.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Web.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.Xpo.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraCharts.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraReports.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.XtraReports.v25.2.Web, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
...
</assemblies>
Note
When using the ASP.NET MVC 5 framework, you should add the DevExpress.Web. Mvc5.v25.2 assembly instead of the DevExpress.Web. Mvc.v25.2 assembly, as shown in the code sample below.
<assemblies>
...
<add assembly="DevExpress.Web.Mvc5.v25.2, Version=25.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
...
</assemblies>
The next step is to register the DevExpress HTTP handler, required namespaces and DevExpress configuration section in the application’s configuration files.
Important
If you create a backend reporting application (without UI), only step 1 (Register the ASPxHttpHandlerModule service) is mandatory. You can skip steps 2 and 3.
Register the ASPxHttpHandlerModule service in four sections of the application’s Web.config file (system.web/httpModules, system.webServer/modules, system.web/httpHandlers and system.webServer/handlers).
To make the DevExpress Reporting Extensions available for use in web project pages, register the DevExpress namespaces in the ‘system.web.webPages.razor‘ section, which is located within the View folder’s Web.config file.
The DevExpress configuration section manages global configuration options. Register this section in the application’s Web.config file using the following code.
Note
Rebuild the project after changing the Configuration section.
Note
If you create a backend reporting application (without the client part), you can skip this step. Review the following help sections for more information on third-party JavaScript client frameworks in Reporting application:
Register reporting scripts using the ExtensionsFactory.GetScripts (or ExtensionsFactory.RenderScripts, if your project uses the ASPX view engine) method in the View (or Layout View) page’s HEAD or BODY tag. Typically, scripts can be attached to all Views in a central location within the layout View.
<head>
...
@Html.DevExpress().GetScripts(
new Script { ExtensionSuite = ExtensionSuite.Report }
)
...
</head>
Attach style sheets using the ExtensionsFactory.GetStyleSheets extension method in the View page’s HEAD (recommended) or BODY tag. Typically, style sheets can be attached to all Views in a central location within the layout View (before the @RenderBody() expression).
<head>
...
@Html.DevExpress().GetStyleSheets(
new StyleSheet { ExtensionSuite = ExtensionSuite.Report }
)
...
</head>
DevExpress editors are bound to data model fields by using Bind (dataObject, propertyName) methods or using strongly typed helpers, the DevExpressEditorsBinder model binder must be used instead of the default model binder to correctly transfer values from DevExpress editors back to corresponding data model fields.
Specify the DevExpressEditorsBinder as a model binder as follows:
Decorate the Action Method Parameter
Overriding the Default Model Binder
Note
Starting with v12.1, the DevExpressEditorsBinder is automatically defined as a default model binder within projects created with the help of Template Gallery.
At this stage, DevExpress Reporting Extensions are fully functional, so the following steps are optional but can be useful in certain scenarios.
Include the ignore route statements with the following patterns to prevent requests from being passed to a controller.
If you create an MVC project using the standard ASP.NET MVC Web Application template provided by Visual Studio, the project’s Content folder contains the automatically generated Site.css file. Specific type selectors that are defined in this file and relate directly to HTML element types (such as links, input elements, tables and table cells) may affect the appearance of DevExpress MVC Reporting extensions. To fix this problem, clear the style settings defined in the element type selectors. This requirement also applies to your custom CSS files and rules.
Specify the following document type for all Views to ensure proper operation of DevExpress MVC Reporting Extensions:
You can now use DevExpress MVC Reporting Extensions in your ASP.NET MVC application. This example uses the ReportDesigner extension (the project was initially created using the ASP.NET MVC 4 Web Application template). Add the following code to the Index View page.
@Html.DevExpress().ReportDesigner(settings => {
settings.Name = "ReportDesigner";
settings.SaveCallbackRouteValues = new { Controller = "Home", Action = "ReportDesigner_Save" };
}).Bind(new DevExpress.XtraReports.UI.XtraReport()).GetHtml()
After building and running the application, the Index page looks as follows:
See Also
Manual Integration into an Existing Project
Redistribution and Deployment (ASP.NET MVC Reporting)
Create a Report in Visual Studio