[Expand]General Information
[Expand]WinForms Controls
[Collapse]ASP.NET Controls and MVC Extensions
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]ASP.NET WebForms Controls
 [Collapse]ASP.NET MVC Extensions
  [Expand]Product Information
  [Expand]Getting Started
  [Collapse]Common Concepts
    Web Application Project Templates
    Insert Extension Wizard
    Data Binding
   [Expand]Applying Themes
    Client-Side API
    Declaring Server-Side Event Handlers
    Using Callbacks
    Passing Values to a Controller Action through Callbacks
    Using Extensions in Razor Views
  [Expand]Grid View
  [Expand]Tree List
  [Expand]Card View
  [Expand]Pivot Grid
   Rich Text Editor
  [Expand]Site Navigation and Layout
  [Expand]HTML Editor
  [Expand]Vertical Grid
  [Expand]Data Editors
  [Expand]Docking and Popups
  [Expand]File Management
  [Expand]Data and Image Navigation
  [Expand]Multi-Use Site Extensions
  [Expand]Spell Checker
  [Expand]Query Builder
 [Expand]Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)


Templates allow you to quickly extend built-in functionality and introduce new capabilities with minimum effort. The DevExpress MVC extensions provide you with the ability to create templates for various extension elements.

Templates can be defined at different object levels at the same time (e.g., at the extension level and the item level). In this case, templates created at a lower level in the logical tree take precedence over other templates for the same element created at a higher level (e.g., a template defined at the item level has precedence over the same element template created at the extension level).

The Set_ElementName_TemplateContent methods are provided to define an element template.

Expanded Defining templates in partial view pages

For each template type you want to use, create a Partial View (a .cshtml or .vbhtml) and provide it with the required content markup. To use this Partial View within a template, call the Html.RenderPartial helper method in template implementation.

Note that the method delegates that enable you to implement templates give you access to a container object within which a template is instantiated. A template container object typically exposes useful information identifying the templated element (for instance, for a grid column header these might be the corresponding column, the header's current location - in the header section, Group Panel, or Customization Window, etc.). Depending upon your application logic, you may or may not use this information when composing templates. The following options are available.

  • Without Passing a Template Container

    If a template is simple and its content does not depend on the information provided by a template container, you do not have to pass a template container object to a partial view. You can define the template contents by using a HTML markup.


    Partial View ("MyMenuItem"):

    Note that you can do this more easily by using another method overload that accepts a string as a parameter.


  • Passing a Template Container as a Model to a Partial View

    If you dynamically compose a template based on template container information, you can pass a template container object to a partial view page as a Model. Use the Html.RenderPartial method's model parameter for this purpose.


    Partial View ("MyMenuItem"):

  • Passing Template Container via ViewData

    You can also pass a template container object to a partial view page as a part of the ViewData by using the Html.RenderPartial method's viewData parameter.


    Partial View ("MyMenuItem"):

Expanded Defining templates in delegate methods directly

If you do not want to use partial views for some reason, and need to entirely define template contents within a delegate method implementation, you can do this using the following options.

  • Using DevExpress extensions as child controls

    You can safely compose a template with the use of DevExpress extensions, which can be rendered with either the ExtensionBase.Render or ExtensionBase.GetHtml method.


  • Using ViewContext.Writer.Write

    If you need to use expressions and an HTML markup, and then combine them with server code within template contents, you can embed a HTML markup by using the ViewContext.Writer.Write method.


  • Using HtmlHelper class

    You can implement an extension method for the HtmlHelper in order to access it in the Controller (not a View) scope. To implement this functionality, you may pass an HtmlHelper object to some static method that creates DevExpress extension settings with templates. At first, you may create some class to get extension settings shared between Views.

    Controller code:

    After writing methods to get the settings, you may use this class in various Partial Views as your needs dictate.

    Partial view code (ASPX):

Is this topic helpful?​​​​​​​