New to Telerik UI for ASP.NET Core? Download free 30-day trial

Razor Page

This article describes how to configure a Remote DataSource of a Telerik DropDownList in a RazorPage scenario.

In order to set up the DropDownList component bindings, you need to configure the Read method of its DataSource instance. The URL in this method should refer the name of the method in the PageModel. In this method, you can also pass additional parameters, such as filter string and antiforgery token (see dataFunction). See the implementation details in the example below, and for the full project with RazorPages examples, visit our GitHub repository.

    @inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
    @Html.AntiForgeryToken()

    @(Html.Kendo().DropDownList()
            .Name("products")
            .DataTextField("ShipName")
            .DataValueField("ShipCity")
            .HtmlAttributes(new { style = "width:300px;" })
            .AutoBind(false)
            .Filter(FilterType.Contains)      
            .DataSource(ds => ds
                .Custom()
                .Transport(transport => transport
                    .Read(read => read
                        .Url("/DropDownList/DropDownListCrudOps?handler=Read").Data("dataFunction")
                    ))
                    .ServerFiltering(true)
                )
            )

<kendo-dropdownlist name="products"
                    datatextfield="ShipName"
                    datavaluefield="ShipCity"
                    auto-bind="false"
                    filter="FilterType.Contains">
    <datasource server-filtering="true">
        <transport>
            <read url="@Url("/DropDownList/DropDownListCrudOps?handler=Read")" data="dataFunction" />
        </transport>
    </datasource>
</kendo-dropdownlist>
    <script>
        function dataFunction() {
            var value = $("#products").getKendoDropDownList().filterInput.val();
            return {
                __RequestVerificationToken: kendo.antiForgeryTokens().__RequestVerificationToken,
                filterValue: value
            };
        }   
    </script>
   public JsonResult OnGetRead(string filterValue)
        {
            if (filterValue != null)
            {
                //orders is the DBContext
                var filteredData = orders.Where(p => p.ShipName.Contains(filterValue)); 
                return new JsonResult(filteredData);
            }
            return new JsonResult(orders);
        }

See Also

In this article