How to Integrate ASP.NET MVC Reporting Extensions Into an Existing Project
9 min to read
This topic explains how to manually 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 manually incorporate DevExpress Reporting Extensions for ASP.NET MVC into your project.
DevExpress.Web.Mvc.v19.2 (or DevExpress.Web.Mvc5.v19.2 if using ASP.NET MVC 5)
Typically, after installation, the required DevExpress assemblies have already been registered in the GAC. So, 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.
The version numbers and public key mentioned in this document may differ depending on the product version you purchased.
You can then 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.
Register the Required Settings in the Application's Configuration Files
The next step is to register the DevExpress HTTP handler, required namespaces and DevExpress configuration section in the application's configuration files.
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 within web project pages, register the required DevExpress namespaces in the 'system.web.webPages.razor' section, which is located within the View folder's Web.config file.
Different aspects of DevExpress functionality can be centrally controlled through configuration options provided by a specially designed DevExpress configuration section. Register this section in the application's Web.config file using the following code.
To include these script files in a client application, do one of the following:
Include these client-side libraries on the web page automatically by adding the "resources" section to the application's Web.config file, as shown below.
For a list of web browsers supported by the Document Viewer, refer to the following document: Supported Browsers.
Then, register reporting scripts using the ExtensionsFactory.GetScripts (or ExtensionsFactory.RenderScripts, if your project uses the ASPX view engine) method within 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.
To attach the required style sheets, use the ExtensionsFactory.GetStyleSheets extension method within 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).
When 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.
You can specify DevExpressEditorsBinder as a model binder in the following manners.
Decorating the Parameter of Action Method
You can declare DevExpressEditorsBinder as a parameter attribute on an action method: ([ModelBinder(typeof(DevExpressEditorsBinder))]).
Public Shared Sub RegisterRoutes(routes As RouteCollection)
' Ignore route statements.
' Route definitions.
If you use the ASP.NET MVC 3 framework, you can find the route definition in the ~/Global.asax.cs file. If you use the ASP.NET MVC 4 or 5 framework, the route definition is placed in the ~/App_Start/RouteConfig.cs file by default.
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.
Using the following document type of Views to ensure that DevExpress MVC Reporting Extensions operate properly is recommended.
Check and correct (if necessary) the document type for all Views containing DevExpress MVC Reporting Extensions and/or document type of layout pages used by Views.
Add Extension Code
You can now use DevExpress MVC Reporting Extensions within 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.