# Configure a Custom DataSource for the Grid in Razor Pages

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Grid for Progress® Telerik® UI for ASP.NET Core</td>
 </tr>
 <tr>
  <td>Product</td>
  <td>DataSource for Progress® Telerik® UI for ASP.NET Core</td>
 </tr>
</table>

## Description

How can I configure a custom DataSource for the Grid HtmlHelper that is used in a Razor Page?

## Solution

The snippet below shows how to configure the DataSource.

```
    @(Html.Kendo().Grid<Telerik.Examples.RazorPages.Models.Customer>().Name("grid")
        .AutoBind(false)
        .Columns(x =>
        {
            x.Bound(p => p.Address);
            x.Bound(p => p.ClockOut).EditorTemplateName("TimePicker").Format("{0:hh:mm tt}");
            x.Command(c => c.Edit());
        })
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .DataSource(d =>
            d.Custom()
            .Transport(t =>
            {
                t.Read(r => r.Action("Grid", "GridCustomDataSource", new { handler = "ReadRecords" }).Type(HttpVerbs.Post));
                t.Update(r => r.Action("Grid", "GridCustomDataSource", new { handler = "UpdateRecord" }).Type(HttpVerbs.Post));
                t.ParameterMap("parameterMap");
            })
            .Schema(s => s.Model(m =>
            {
                m.Id(i => i.CustomerId);
                m.Field("ClockOut", typeof(DateTime?));
            }))
            .PageSize(10)                
        )
        .Pageable()
    )

    <script>
        function parameterMap(options, operation) {
            if (operation === "update") {            
                options.ClockOut = options.ClockOut.toUTCString();
                return options;
            }
        }
    </script>

    <script>
        $(function () {
            var grid = $("#grid").data("kendoGrid");
            grid.dataSource.transport.options.read.beforeSend = function (req) {
                req.setRequestHeader('RequestVerificationToken', $('input:hidden[name="__RequestVerificationToken"]').val());
            };
            grid.dataSource.transport.options.update.beforeSend = function (req) {
                req.setRequestHeader('RequestVerificationToken', $('input:hidden[name="__RequestVerificationToken"]').val());
            };
            grid.dataSource.read();
        });
    </script>
```

For the complete implementation on how to configure a custom DataSource to properly populate a Telerik UI Grid HtmlHelper for ASP.NET Core in a Razor Page, refer to [this GitHub project](https://github.com/telerik/ui-for-aspnet-core-examples/tree/master/Telerik.Examples.RazorPages).

## More ASP.NET Core Grid Resources

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

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

* [ASP.NET Core DataGrid Product Page](https://www.telerik.com/aspnet-core-ui/grid)

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

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

## See Also

* [Client-Side API Reference of the Grid for ASP.NET Core](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET Core](https://docs.telerik.com/aspnet-core/api/grid)
* [Telerik UI for ASP.NET Core Breaking Changes](https://www.telerik.com/aspnet-core-ui/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET Core Knowledge Base](https://docs.telerik.com/aspnet-core/knowledge-base)
