Skip to main content

MVCxDiagramItemUpdateValues<TItem, TKey>.MapInsertedItemKey(TItem, TKey) Method

Specifies the key value of the inserted item.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.1.dll

NuGet Package: DevExpress.Web.Mvc5

Declaration

public void MapInsertedItemKey(
    TItem item,
    TKey itemKey
)

Parameters

Name Type Description
item TItem

The inserted item.

itemKey TKey

The inserted item’s key.

Remarks

The Diagram extension builds a diagram based on the nodes’ and edges’ key values.

The extension retrieves keys for all bound items (nodes and edges) from a data source. If a new item is created by a user, you should obtain the item’s key and send it to the extension. The key can be autogenerated by a data source on item inserting, or created manually in code. Call the MapInsertedItemKey method for each created/inserted data item to map keys to items.

The GetBatchUpdateResult method combines all mapped keys and returns them as an action result to the client instance of the Diagram extension.

Note

If an item’s key is not determined, the “The inserted item key is undefined. Use the MVCxDiagramItemUpdateValues.MapInsertedItemKey method to specify the key value for a newly inserted {2}.“ exception is thrown.

@Html.DevExpress().Diagram(settings => {
    settings.Name = "Diagram";

    settings.BatchUpdateRouteValues = new { Controller = "DataBinding", Action = "LinearUpdate" };

    settings.Mappings.Node.Key = "ID";
    settings.Mappings.Node.ParentKey = "ParentID";
    settings.Mappings.Node.Text = "DepartmentName";

    settings.SettingsAutoLayout.Type = DevExpress.Web.ASPxDiagram.DiagramAutoLayout.Tree;

}).Bind(Model).GetHtml()
public ActionResult LinearUpdate(MVCxDiagramNodeUpdateValues<EditableDepartment, int> nodeUpdateValues) {
    foreach(var item in nodeUpdateValues.Update)
        DepartmentProvider.Update(item);
    foreach(var itemKey in nodeUpdateValues.DeleteKeys)
        DepartmentProvider.Delete(itemKey);
    foreach(var item in nodeUpdateValues.Insert) {
        var insertedItem = DepartmentProvider.Insert(item);
        nodeUpdateValues.MapInsertedItemKey(item, insertedItem.ID);
    }
    return DiagramExtension.GetBatchUpdateResult(nodeUpdateValues);
}

Run Demo: Tree from Linear Data Structure

See Also