Skip to main content
A newer version of this page is available. .

Strongly-Typed Helpers

  • 2 minutes to read

Strongly-typed helper methods help you set up DevExtreme-based controls. They allow view code validation at compile-time, provide full IntelliSense support, and automatically add client-side validation based on Data Annotations.

You can use two kinds of DevExtreme strongly-typed helpers:

  • ControlFor - Methods with the For suffix (CalendarFor, DateBoxFor, etc.) are used to configure standalone editors. These methods are similar to the built-in ASP.NET Core strongly-typed helpers like TextBoxFor.

    These methods bind controls to model properties specified by lambda expressions. This approach allows you to configure the controls without the use of string constants.

    Note

    To bind a control to a model property, specify a model in the @model directive.

    The example below demonstrates the DateBoxFor method that creates the DateBox control and binds it to the OrderViewModel model’s OrderDate property.

    @model OrderViewModel
    
    @(Html.DevExtreme().DateBoxFor(m => m.OrderDate))
    

    ControlFor methods can be used in partial views that have their own models. The example below demonstrates a partial view that uses DevExtreme strongly-typed helpers (DateBoxFor, TextBoxFor) along with the built-in helpers (LabelFor, ValidationMessageFor).

    @model OrderViewModel
    
    @using (Html.BeginForm()) {
        @Html.LabelFor(m => m.OrderDate)
        @Html.DevExtreme().DateBoxFor(m => m.OrderDate)
        @Html.ValidationMessageFor(m => m.OrderDate)
    
        @Html.LabelFor(m => m.ShipCity)
        @Html.DevExtreme().TextBoxFor(m => m.ShipCity)
    
        @Html.DevExtreme().Button().Text("Save").UseSubmitBehavior(true)
    }
    
  • Control<T> - Used to configure controls that have bindable items:

    • DataGrid (columns and summaries)
    • TreeList (columns)
    • PivotGrid (fields)
    • Form (items)

    Note

    To bind a control to a model, specify the model in a helper method as a type parameter. The control will represent data from this model, not from a current view’s model.

    The example code below adds the DataGrid that is strongly-typed to the OrderViewModel type. The AddFor() method configures grid columns. This method binds a column to a model property specified by a lambda expression.

    @model IndexModel
    @* the IndexModel model is not used for the DataGrid control *@
    
    ...
    
    @(Html.DevExtreme().DataGrid<OrderViewModel>()
        .Columns(columns => {
            columns.AddFor(m => m.OrderDate);
            columns.AddFor(m => m.ShipCity);
        })
    )
    

More examples are available in our demos and sample applications.