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

Access Current Model in the Grid Popup

Environment

ProductTelerik UI for ASP.NET MVC Grid
Product Version2025.1.227

Description

How can I access the currently editable data item in the Popup editor template of the Telerik UI for ASP.NET MVC Grid?

Solution

You can implement this requirement as follows:

  1. Enable the Popup editing of the Grid and define its custom editor template:

    Razor
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("CustomPopUpEditor").AdditionalViewData(new {GridName = GridName}))
  2. Access the additional data in the custom Popup editor template:

    Razor
    @{
        string ChildGridName = "PopupGrid";
    }
    
    <script>
        function getCurrentParentId() {
            var uid = $("#@ChildGridName").closest("[data-uid]").data("uid");
            var parentGrid = $("#@ViewData["GridName"]").data("kendoGrid");
            var model = parentGrid.dataSource.getByUid(uid);
            return { parrentGridRecordId: model.OrderID };
        }
    </script>
    
    @(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridEditingPopUpAccessModel.Models.Order>()
        .Name(ChildGridName)
        .Columns(columns => {
            columns.Bound(p => p.OrderID);
            columns.Bound(p => p.OrderDescription);
            columns.Bound(p => p.OrderDate);
        })
        .Pageable()
        .Scrollable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(false)
            .Model(model => {
                model.Id(p => p.OrderID);
            })
            .Read(read => read.Action("ForeignKeyColumn_Read", "Home").Data("getCurrentParentId"))
        )
    )

To see the complete example, refer to the ASP.NET MVC application in the UI for ASP.NET MVC Examples repository.

More ASP.NET MVC Grid Resources

See Also