# Handle Cascading DropDownLists within the Grid

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC DropDownList, <br/>
           Telerik UI for ASP.NET MVC Grid
  </td>
 </tr>
 <tr>
  <td>Product Version</td>
  <td>Created with version 2024.4.1112</td>
 </tr>
</table>

## Description

How can I implement cascading ASP.NET MVC DropDownLists within a ASP.NET MVC Grid component?

## Solution

You can achieve this requirement using editor templates for the Grid columns by following the next steps:

1. Define the Grid and its columns:

```Razor HtmlHelper
@(Html.Kendo().Grid<License>()
    .Name("inlineGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.LicenseId).Hidden();
        columns.Bound(p => p.CustomerId);
        columns.Bound(p => p.VendorId);
        columns.Bound(p => p.ProductId);
        columns.Command(p => p.Edit().Text("Edit")).Width(80);
    })
    .HtmlAttributes(new { style = "height: 430px;" })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(p => p.LicenseId))
        .Create(create => create.Action("Create", "Home"))
        .Read(read => read.Action("Read", "Home"))
        .Update(update => update.Action("Update", "Home"))
    )
)
```

2. Decorate each Model property with the `UIHint` Data Annotation attribute to speify the name of the view that contains the custom editor (for example, the DropDownList).

```C# Model
public class License
{
    [Required(ErrorMessage = "LicenseId is required")]
    public int LicenseId { get; set; }

    [UIHint("CustomerId")]
    [Required(ErrorMessage = "CustomerId is required")]
    public int CustomerId { get; set; }

    [UIHint("VendorId")]
    [Required(ErrorMessage = "VendorId is required")]
    public int VendorId { get; set; }

    [UIHint("ProductId")]
    [Required(ErrorMessage = "ProductId is required")]
    public int ProductId { get; set; }
}
```

3. Add a view for each editor in the `Views/Shared/EditorTemplates` folder. Ensure that the names of the views match the specified names in the `UIHint` attributes.

* `CustomerId` DropDownList:

```Razor HtmlHelper
@using Kendo.Mvc.UI
@model int

@(Html.Kendo().DropDownListFor(m => m)
    .ValuePrimitive(true)
    .OptionLabel("Select Customer...")
    .DataTextField("CustomerName")
    .DataValueField("CustomerId")
    .DataSource(dataSource =>
    {
        dataSource.Read(read => read.Action("GetCustomers", "Home"))
                .ServerFiltering(true);
    })
)
@Html.ValidationMessageFor(m => m)
```

* `VendorId` DropDownList:

```Razor HtmlHelper
@using Kendo.Mvc.UI
@model int

@(Html.Kendo().DropDownListFor(m => m)
    .AutoBind(false)
    .ValuePrimitive(true)
    .OptionLabel("Select Vendor...")
    .DataTextField("VendorName")
    .DataValueField("VendorId")
    .DataSource(dataSource =>
    {
        dataSource.Read(read => read.Action("GetVendors", "Home").Data("filterVendors"))
                .ServerFiltering(true);
    })
    .CascadeFrom("CustomerId")
)

@Html.ValidationMessageFor(m => m)
```

* `ProductId` DropDownList:

```Razor HtmlHelper
@using Kendo.Mvc.UI
@model int

@(Html.Kendo().DropDownListFor(m => m)
    .AutoBind(false)
    .ValuePrimitive(true)
    .OptionLabel("Select Product...")
    .DataTextField("ProductName")
    .DataValueField("ProductId")
    .DataSource(dataSource =>
    {
        dataSource.Read(read => read.Action("GetProducts", "Home").Data("filterProducts"))
                .ServerFiltering(true);
    })
    .CascadeFrom("VendorId")
)

@Html.ValidationMessageFor(m => m)
```

To see the complete example, refer to the ASP.NET MVC project on how to [configure the Grid to handle its cascading DropDownList editors](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/GridEditingWithCascadingDropDownLists) when the Grid is set up for Popup or InLine edit mode.

## More ASP.NET MVC DropDownList Resources

* [ASP.NET MVC DropDownList Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/dropdownlist/overview)

* [ASP.NET MVC DropDownList Demos](https://demos.telerik.com/aspnet-mvc/dropdownlist)

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

* [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 DropDownList for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/dropdownlist)

* [Server-Side API Reference of the DropDownList for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/dropdownlist)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)

* [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)
