# Saving Changes in All Grids

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Progress Telerik UI for ASP.NET MVC Grid</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.1.314 version</td>
 </tr>
</table>

## Description

How can I consolidate the save operations of all the Telerik UI for ASP.NET MVC Grids through an external **Save** button?

## Solution

To achieve the desired scenario:

1. Create an external **Save** Button and subscribe to its [`Click`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/buttoneventbuilder#clicksystemstring) event.
2. Within the `Click` handler, loop through all utilized Grids by accessing them through the `.k-grid` class and save the changes by using the [`saveChanges()`](https://docs.telerik.com/kendo-ui/api/ui/grid/methods/savechanges) method.

```Razor Index.cshtml
    @(Html.Kendo().Button()
      .Name("saveBtn")
      .Content("Save changes")
      .Events(e=>e.Click("onClickHandler"))
    )

    <h1>Grid #1</h1>
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
        .Name("grid1")
        .Columns(columns => {
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.UnitPrice).Width(140);
            columns.Command(command => command.Destroy()).Width(150);
        })
        .ToolBar(toolbar => {
            toolbar.Create();
        })
        .Scrollable()
        .Height(200)
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .PageSize(20)
            .ServerOperation(false)
            .Model(model => model.Id(p => p.ProductID))
            .Create("Editing_Create", "Grid")
            .Read("Editing_Read", "Grid")
            .Update("Editing_Update", "Grid")
            .Destroy("Editing_Destroy", "Grid")
        )
    )

    <h1>Grid #2</h1>
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
        .Name("grid2")
        .Columns(columns => {
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.UnitPrice).Width(140);
            columns.Command(command => command.Destroy()).Width(150);
        })
        .ToolBar(toolbar => {
            toolbar.Create();
        })
        .Height(200)
        .Scrollable()
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .PageSize(20)
            .ServerOperation(false)
            .Model(model => model.Id(p => p.ProductID))
            .Create("Editing_Create", "Grid")
            .Read("Editing_Read", "Grid")
            .Update("Editing_Update", "Grid")
            .Destroy("Editing_Destroy", "Grid")
        )
    )
```

```JS script.js
    <script type="text/javascript">
            function onClickHandler(e){
                $(".k-grid").each(function (index, value) {
                     var grid = $(this).data("kendoGrid"); // Get the reference of the current Grid widget instance.
                     grid.saveChanges(); // Save the changes for the current Grid widget instance.
                });
            }
    </script>
```

For the complete implementation of the suggested approach, refer to the [Telerik REPL example on saving all changes in  Grids](https://netcorerepl.telerik.com/QnEeQhEV26Fi4SlI30).

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid  for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid  for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)
* [Telerik REPL: Save Changes in All Grids](https://netcorerepl.telerik.com/QnEeQhEV26Fi4SlI30)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
