自定义数据绑定
您可以为数据绑定配置Telerik UI下拉列表,以使用自定义数据源,从而绑定到ToDataSourceResult
实例。
创建一个呈现视图的操作方法。
public ActionResult Index() {return View();}
创建一个新的动作方法并传递产品表作为JSON结果。
public JsonResult GetProducts([DataSourceRequest] DataSourceRequest请求){NorthwindDataContext northwind = new NorthwindDataContext();返回Json (northwind.Products.ToDataSourceResult(请求));}
添加一个ajax绑定的下拉列表。
@(Html.Kendo().DropDownList() . name ("productDropDownList") //下拉列表的名称是必须的。它指定了“id”小部件的属性。.DataTextField(“ProductName”)/ /指定产品的哪个属性使用DropDownList文本。.DataValueField(“ProductID”)/ /指定产品的哪个属性使用DropDownList价值。.DataSource(源= > {source.Custom () .ServerFiltering(真正的).Type (aspnetmvc-ajax) / /设置这个类型,如果你想使用DataSourceRequest和ToDataSourceResult实例。.Transport(运输= >{运输。读(“GetProducts”、“家”);}) . schema (schema => {schema.Data("Data")) //定义[Data](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data)选项。Total("Total");//定义[total](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total)选项。});}))
//定义[total](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total)选项