New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Data Binding

Updated on Nov 5, 2025

The Telerik UI Diagram for ASP.NET MVC provides built-in DataSource options that allow you to bind the Diagram to remote data. You can bind to hierarchical data structures or use separate data sources for shapes and connections.

The following table summarizes the available binding approaches and their use cases:

Binding ApproachDescriptionWhen to UseData Source Configuration
Hierarchical Data BindingBinds to a single data source with parent-child relationships defined by a children fieldFor tree-like structures such as organizational charts, mind maps, or any hierarchical data where relationships are nestedUse .DataSource() with .Model(m => m.Children("fieldName"))
ShapeDataSource + ConnectionsDataSourceUses separate data sources for shapes and connections, allowing independent CRUD operationsWhen shapes and connections need to be managed separately, or when you need full CRUD capabilities for both elementsUse .DataSource(ds => ds.ShapeDataSource()...) for shapes and .ConnectionsDataSource() for connections

Binding to Hierarchical Data

The Diagram supports binding to hierarchical data structures where parent-child relationships are defined. This is useful for organizational charts, mind maps, and other tree-like structures.

To bind the Diagram to hierarchical data, configure the DataSource with a model that specifies the Children field, which holds the child records.

Razor
@(Html.Kendo().Diagram()
    .Name("diagram")
    .DataSource(dataSource => dataSource
        .Read(read => read
            .Action("_OrgChart", "Diagram")
        )
        .Model(m => m.Children("Items"))
    )
    .ShapeDefaults(sd => sd
        .Content(c => c
                  .FontSize(17)
                  .Color("#444")
              )
    )
)

The server-side controller returns JSON data with the hierarchical structure:

C#
public ActionResult _OrgChart()
{
    return Json(DiagramDataRepository.OrgChart());
}

Using ShapeDataSource and ConnectionsDataSource

For more complex scenarios where shapes and connections must be managed separately, use the ShapeDataSource() and ConnectionsDataSource() methods. This approach enables CRUD operations on both shapes and connections independently.

Razor
@(Html.Kendo().Diagram<OrgChartShape, OrgChartConnection>()
    .Name("diagram")
    .DataSource(d => d
        .ShapeDataSource()
        .Model(m =>
        {
            m.Id(s => s.Id);
            m.Field(s => s.Id).Editable(false);
            m.Field(s => s.JobTitle);
            m.Field(s => s.Color);
        })
        .Read("ReadShapes", "DiagramData")
        .Create("CreateShape", "DiagramData")
        .Update("UpdateShape", "DiagramData")
        .Destroy("DestroyShape", "DiagramData")
    )
    .ConnectionsDataSource(d => d
        .Model(m =>
        {
            m.Id(c => c.Id);
            m.Field(c => c.Id).Editable(false);
            m.Field(c => c.Text).Editable(false);
            m.From(c => c.FromShapeId);
            m.To(c => c.ToShapeId);
            m.FromX(c => c.FromPointX);
            m.FromY(c => c.FromPointY);
            m.ToX(c => c.ToPointX);
            m.ToY(c => c.ToPointY);
        })
        .Read("ReadConnections", "DiagramData")
        .Create("CreateConnection", "DiagramData")
        .Update("UpdateConnection", "DiagramData")
        .Destroy("DestroyConnection", "DiagramData")
    )
    .ShapeDefaults(sd => sd
        .Content(c => c
            .FontSize(17)
            .Color("#444")
        )
    )
    .ConnectionDefaults(cd => cd
        .Stroke(s => s
            .Color("#586477")
            .Width(2)
        )
    )
)

The ShapeDataSource() method configures the data source for diagram shapes, while ConnectionsDataSource() handles the connections between shapes. This separation allows for independent CRUD operations on shapes and connections.

Customizing the Appearance

To create a network of visuals and customize the appearance of the Diagram, set its Visual configuration.

Razor
    @(Html.Kendo().Diagram()
              .Name("diagram")
              .DataSource(dataSource => dataSource
                  .Read(read => read
                      .Action("_OrgChart", "Diagram")
                  )
                  .Model(m => m.Children("Items"))
              )
              .Editable(false)
              .Layout(l => l.Type(DiagramLayoutType.Layered))
              .ShapeDefaults(sd => sd
                  .Visual("visualTemplate")
              )
              .ConnectionDefaults(cd => cd
                  .Stroke(s => s
                      .Color("#979797")
                      .Width(2)
                  )
              )
              .Events(events => events.DataBound("onDataBound"))
    )

Next Steps

See Also