Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]ASP.NET WebForms Controls
 [Collapse]ASP.NET MVC Extensions
  [Expand]Product Information
  [Collapse]Getting Started
   [Collapse]Integration into an ASP.NET MVC Project
     Manual Integration into an Existing Project
     Integration into an Existing Project Using Wizards
    How It Works
  [Expand]Common Concepts
  [Expand]Grid View
  [Expand]Card View
  [Expand]Vertical Grid
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]HTML Editor
  [Expand]Image and Data Browsing
  [Expand]Docking and Popups
  [Expand]Navigation and Layout Extensions
  [Expand]File Management
  [Expand]Multi-Use Site Extensions
  [Expand]Charts
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Tree List
  [Expand]Data Editor Extensions
  [Expand]Report Extensions
  [Expand]SpellChecker
 [Expand]Localization
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Integration into an Existing Project Using Wizards

This topic explains how to incorporate DevExpress Extensions for ASP.NET MVC into an existing ASP.NET MVC application using wizards. If you wish to create a new ASP.NET MVC application and use a DevExpress ASP.NET MVC extension within it, create a new application using specially designed DevExpress project templates.

You can use the DevExpress Project Wizard or the Insert Extension Wizard to simplify the integration of DevExpress ASP.NET MVC extensions into your project.

This document consists of two step-by-step tutorials.

Expanded Integrating DevExpress ASP.NET MVC Extensions into an Existing Project using the Project Wizard

To integrate DevExpress ASP.NET MVC extensions into an existing project using the Project Wizard, perform the following steps.

  1. Open your ASP.NET MVC project. In the main menu of Visual Studio, click the DEVEXPRESS submenu and select ASP.NET Controls v17.1 | Run Wizard to Update Project....

  2. This invokes the DevExpress ASP.NET MVC Project Wizard. This wizard allows you to customize the settings specific to DevExpress ASP.NET MVC Extensions (e.g., you can select the required theme or select the localization). After the required settings have been specified, click Update Project.

    The wizard adds the required assemblies to the project, and makes all necessary changes to the Web.config file.

  3. Attach the required JavaScript files.

    All the DevExpress ASP.NET MVC extensions require attaching the jQuery library and some of them also require attaching additional libraries.

    Important

    If you attach the jQuery scripts manually, the jQuery script must be attached before attaching the DevExpress client script files, in order to avoid possible errors.

    If you bundled your JavaScript files, the bundle with jQuery library must be attached before attaching the DevExpress client script files. By default, the standard ASP.NET MVC 4 and 5 projects locate reference to the JavaScript bundle at the bottom of the "_Layout.cshtml" page.

    For an ASP.NET MVC extension to work properly, you either need to manually add the required external libraries, or enable the control to load them automatically by adding the following references to the "resources" section in the Web.config file.

    These settings specify the following resources.

    • "ThirdParty" - adds references to external libraries required by a specific control. For a complete list of these references, see Embedding Third-Party Libraries.

    • "DevExtreme" - adds a reference to the DevExtreme package. For a complete list of these references, see the "Integration with 3rd-Party Libraries and Frameworks" section of the Introduction to DevExtreme document.

    The above resources are automatically added to the Web.config file on adding a DevExpress web control to a new application created using the DevExpress template gallery. In this case, all necessary client-side libraries are automatically passed to the client.

    When manually adding such controls to a web page, you need to explicitly specify which of the client libraries must be deployed on the client by the control. By default, on adding such a DevExpress control, it loads only the DevExtreme library to a web page without loading third-party libraries.

    To avoid automatic loading of any libraries by a control (e.g., when such libraries are already referenced on the web page), declare an empty "resources" section and manually attach DevExtreme resources and the required third-party libraries (such as jQuery and Globalize) to the web page.

    Deleting the DevExpress "resources" section from the Web.config file will enable the default behavior (with automatic loading of only DevExtreme, without adding third-party libraries).

    On adding such DevExpress controls to a project, the "resources" section should automatically become registered in the application's Web.config file.

    When updating your project version using the Project Converter, you are required to manually register this section in the Web.config file.

    To attach the required DevExpress JavaScript files, use the ExtensionsFactory.GetScripts (or ExtensionsFactory.RenderScripts, if your project uses the ASPX view engine) method within the View page's HEAD or BODY tag. Typically, scripts can be attached to all Views in a central location within the layout View.

    If the "resources" section of an application's Web.config file contains a reference to the "ThirdParty" and/or "DevExtreme" libraries, the GetScripts method will attach the corresponding libraries and additional resources to the View.

    The jQuery scripts are typically located within the Scripts folder after creating a new ASP.NET MVC Web Application project.

    View (or layout View) Code (Razor):

  4. Attach the required style sheets.

    To attach the required style sheets, use the ExtensionsFactory.GetStyleSheets extension method within a View page's HEAD (recommended) or BODY tag. If you are planning to use DevExpress ASP.NET MVC extensions within multiple views of your project, you can attach style sheets to all Views in a central location such as the "_Layout.cshtml" shared View page (before the @RenderBody() expression). If you plan to use DevExpress Extensions within a single View, it is recommended that you attach the style sheets to the required View.

    The code sample below demonstrates how to attach style sheets for the specified extension set(s).

    View (or layout View) Code (Razor):

    Note

    If you have not selected the required theme within the DevExpress Project Wizard, the Default theme will be applied. To select the required theme or change any other DevExpress extension-specific settings, run the wizard again and define these settings.

    Different options for attaching and applying DevExpress themes are described in the Applying Themes section of the documentation.

  5. You should include the ignore route statements with the following patterns to prevent requests from being passed to a controller:

    • {resource}.axd/{*pathInfo} - for the Web resource files (e.g., scripts, styles);
    • {resource}.ashx/{*pathInfo} - for the ASHX handler, which processes the file upload functionality of DevExpress ASP.NET MVC extensions (e.g., UploadControl, FileManager, HtmlEditor).

    In the registered route collection, add the required ignore route statements above the other route definitions:

    Tip

    If you use the ASP.NET MVC v.3 framework, you can find the route definition in the ~/Global.asax.cs file. If you use the ASP.NET MVC v.4 or v.5 framework, the route definition is placed to the ~/App_Start/RouteConfig.cs file by default.

  6. Override the Default Model Binder.

    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))])

      Controller:
    • Overriding the Default Model Binder

      You can assign DevExpressEditorsBinder to the ModelBinders.Binders.DefaultBinder property to replace the global default model binder.

      Global.asax:
    Note

    Starting with v2012 vol 1, DevExpressEditorsBinder is automatically defined as a default model binder within projects created with the help of DevExpress MVC project templates.

  7. If you create an ASP.NET 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 adversely affect the appearance of DevExpress MVC extensions. To fix this problem, you are required to clear the style settings defined in the element type selectors. This requirement also applies to your custom CSS files and rules, if any.

  8. It is recommended that you use the following document type for Views, to ensure that DevExpress ASP.NET MVC extensions work properly.

    Please check and correct (if necessary) the document type of all Views containing DevExpress ASP.NET MVC extensions and/or the document type of layout pages used by Views.

You can now use DevExpress extensions within your ASP.NET MVC application.

Expanded Integrating DevExpress ASP.NET MVC Extensions into an Existing Project using the Insert Extension Wizard

To integrate DevExpress ASP.NET MVC extensions into an existing project using the Insert Extension Wizard, perform the following steps.

  1. Open your ASP.NET MVC project. Go to the View in which you wish to insert an extension. Focus the line of code where you will insert the extension. Right-click and select the Insert DevExpress MVC Extension v17.1... item in the context menu.

  2. This invokes the Insert Extension Wizard. This wizard allows you to select the required extension, define its settings and add the extension to the View. After specifying the required extension settings, click Insert.

    The wizard automatically generates the code for a DevExpress extension, which is selected and customized via the wizard. The generated code is inserted into the View at the cursor position. After this step, the wizard adds the required assemblies to the project, and makes all necessary changes to the Web.config file.

  3. Attach the required JavaScript files.

    All the DevExpress ASP.NET MVC extensions require attaching the jQuery library and some of them also require attaching additional libraries.

    Important

    If you attach the jQuery scripts manually, the jQuery script must be attached before attaching the DevExpress client script files, in order to avoid possible errors.

    If you bundled your JavaScript files, the bundle with jQuery library must be attached before attaching the DevExpress client script files. By default, the standard ASP.NET MVC 4 and 5 projects locate reference to the JavaScript bundle at the bottom of the "_Layout.cshtml" page.

    For an ASP.NET MVC extension to work properly, you either need to manually add the required external libraries, or enable the control to load them automatically by adding the following references to the "resources" section in the Web.config file.

    These settings specify the following resources.

    • "ThirdParty" - adds references to external libraries required by a specific control. For a complete list of these references, see Embedding Third-Party Libraries.

    • "DevExtreme" - adds a reference to the DevExtreme package. For a complete list of these references, see the "Integration with 3rd-Party Libraries and Frameworks" section of the Introduction to DevExtreme document.

    The above resources are automatically added to the Web.config file on adding a DevExpress web control to a new application created using the DevExpress template gallery. In this case, all necessary client-side libraries are automatically passed to the client.

    When manually adding such controls to a web page, you need to explicitly specify which of the client libraries must be deployed on the client by the control. By default, on adding such a DevExpress control, it loads only the DevExtreme library to a web page without loading third-party libraries.

    To avoid automatic loading of any libraries by a control (e.g., when such libraries are already referenced on the web page), declare an empty "resources" section and manually attach DevExtreme resources and the required third-party libraries (such as jQuery and Globalize) to the web page.

    Deleting the DevExpress "resources" section from the Web.config file will enable the default behavior (with automatic loading of only DevExtreme, without adding third-party libraries).

    On adding such DevExpress controls to a project, the "resources" section should automatically become registered in the application's Web.config file.

    When updating your project version using the Project Converter, you are required to manually register this section in the Web.config file.

    To attach the required DevExpress JavaScript files, use the ExtensionsFactory.GetScripts (or ExtensionsFactory.RenderScripts, if your project uses the ASPX view engine) method within the View page's HEAD or BODY tag. Typically, scripts can be attached to all Views in a central location within the layout View.

    If the "resources" section of an application's Web.config file contains a reference to the "ThirdParty" and/or "DevExtreme" libraries, the GetScripts method will attach the corresponding libraries and additional resources to the View.

    The jQuery scripts are typically located within the Scripts folder after creating a new ASP.NET MVC Web Application project.

    View (or layout View) Code (Razor):

  4. Attach the required style sheets.

    To attach the required style sheets, use the ExtensionsFactory.GetStyleSheets extension method within the View page's HEAD (recommended) or BODY tag. If you are planning to use DevExpress ASP.NET MVC extensions within multiple views of your project, you can attach style sheets to all Views in a central location such as the "_Layout.cshtml" shared View page (before the @RenderBody() expression). If you plan to use DevExpress extensions within a single View only, it is recommended that you attach the style sheets to the required View.

    The code sample below demonstrates how to attach style sheets for the specified extension set(s).

    View (or layout View) Code (Razor):

    After attaching the style sheets, you should define the theme that will be applied to the DevExpress ASP.NET MVC extensions using one of the following approaches.

    • Assign the theme name to the DevExpressHelper.Theme static property. This programmatically applies the theme to all DevExpress extensions within an application.
    • Assign the theme name to the DevExpress Theme Name option in the Web.config file. This declaratively applies the theme to all DevExpress extensions within an application.

    The following code demonstrates how the "Aqua" theme can be globally applied to all DevExpress ASP.NET MVC extensions within an application using the DevExpressHelper.Theme static property.

    Global.asax.cs Code:

    Different options for attaching and applying DevExpress themes are described in the Applying Themes section.

  5. You should include the ignore route statements with the following patterns to prevent requests from being passed to a controller:

    • {resource}.axd/{*pathInfo} - for the Web resource files (e.g., scripts, styles);
    • {resource}.ashx/{*pathInfo} - for the ASHX handler, which processes the file upload functionality of DevExpress ASP.NET MVC extensions (e.g., UploadControl, FileManager, HtmlEditor).

    In the registered route collection, add the required ignore route statements above the other route definitions:

    Tip

    If you use the ASP.NET MVC v.3 framework, you can find the route definition in the ~/Global.asax.cs file. If you use the ASP.NET MVC v.4 or v.5 framework, the route definition is placed to the ~/App_Start/RouteConfig.cs file by default.

  6. Override the Default Model Binder.

    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))])

      Controller:
    • Overriding the Default Model Binder

      You can assign DevExpressEditorsBinder to the ModelBinders.Binders.DefaultBinder property to replace the global default model binder.

      Global.asax:
    Note

    Starting with v2012 vol 1, DevExpressEditorsBinder is automatically defined as a default model binder within projects created with the help of DevExpress MVC project templates.

  7. If you create an ASP.NET 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 adversely affect the appearance of DevExpress MVC extensions. To fix this problem, you are required to clear the style settings defined in the element type selectors. This requirement also applies to your custom CSS files and rules, if any.

  8. It is recommended that you use the following document type for Views to ensure that DevExpress ASP.NET MVC extensions will work properly.

    Be sure to check and correct (if necessary) the document type of all Views containing DevExpress ASP.NET MVC extensions and/or the document type of layout pages used by Views.

The required extension has now been inserted into the View, and you can use all other DevExpress extensions within your ASP.NET MVC application.

Refer to the How It Works topic to learn about the fundamentals of DevExpress ASP.NET MVC extensions.

Expanded See Also

How would you rate this topic?​​​​​​​