# Defining Custom HtmlHelper Methods

## Environment

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

## Description

How can I define my own custom HtmlHelper methods for an arbitrary Telerik UI for ASP.NET MVC component?

## Solution

To achieve the desired result:

1. Create a static [`Extension Method`](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods) to extend the desired type for the utilized configuration of the component.
2. Within the method, implement the desired logic and return the extended type.
3. From there, reference the extension method within the page in which it will be utilized.
4. Finally, invoke the defined extension method inside the component's configuration.

The following example illustrates how to define a custom HtmlHelper method for the Grid:

```Razor Index.cshtml
    @using TelerikExample.Extensions

    @(Html.Kendo().Grid<OrderViewModel>()
         .Name("grid")
         .Columns(columns =>
         {
             columns.Bound(p => p.Discontinued);
             columns.Bound(p => p.Approved);
         })
         .CustomPageable()
         .DataSource(dataSource => dataSource
             .Ajax()
             .PageSize(20)
             .Read(read => read.Action("Orders_Read", "Grid"))
          )
    )
```

```C# GridExtension.cs
    namespace TelerikExample.Extensions
    {
        public static class GridExtension
        {
            public static GridBuilder<T> CustomPageable<T>(this GridBuilder<T> builder)
                where T : class // Custom method for reusing several configartion methods simulatenously.
            {
                return builder
                    .Pageable(conf =>
                    {
                        conf.PreviousNext(true);
                        conf.Numeric(false);
                        conf.Info(false);
                        conf.Input(true);
                    });
            }
        }
    }
```

## 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 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)
