我有一个Kendo网格,而列定义为:
.Columns(columns =>
{
columns.Bound(b => b.Field);
columns.Bound(b => b.OldValue);
columns.Bound(b => b.NewValue);
columns.Bound(b => b.DateImported).Format("{0:dd-MMM-yyyy}");
columns.Bound(b => b.BuildingChangeValidationStatusType).ClientTemplate("#=BuildingChangeValidationStatusType.Value#").Width(250);
columns.Command(command => command.Custom("Update").Click("updateValidation"));
columns.Command(command => { command.Edit(); }).Width(172);
})
BuildingChangeValidationStatusType客户端模板定义为:
@model Rep.Models.BuildingChangeValidationViewModel
@(Html.Kendo().DropDownList()
.Name("BuildingChangeValidationStatusType") // Name of the widget should be the same as the name of the property
.DataValueField("Id")
.DataTextField("Value")
.BindTo((System.Collections.IEnumerable)Model.BuildingChangeValidationStatuses)
)
我想知道如何将Grid的模型传递给客户端模板以便该行:
.BindTo((System.Collections.IEnumerable)Model.BuildingChangeValidationStatuses)
)
会妥善解决。有任何想法吗?
答案 0 :(得分:1)
我通过javascript函数将我需要的数据传递给客户端模板中的DropdownList,从而以不同的方式解决了这个问题。因此,包含下拉列表的客户端模板如下:
@(Html.Kendo().DropDownList()
.Name("BuildingChangeValidationStatusType") // Name of the widget should be the same as the name of the property
.DataValueField("Id")
.DataTextField("Value")
//.BindTo((System.Collections.IEnumerable)Model.BuildingChangeValidationStatuses)
.DataSource(
source => source.Read(read =>
read.Action("BuildingValidationLookups_Read", "Plan").Data("getBuildingId")
)
.ServerFiltering(true)
)
.SelectedIndex(0)
)
注意数据源读取操作,它调用名为“BuildingValidationLookups_Read”的“Plan”控制器上的方法,但也传递从“getBuildingId”javascript函数中检索到的数据,该函数定义为:
function getBuildingId(){
var entityGrid = $("#BuildingValidationGrid").data("kendoGrid");
var selected = entityGrid.dataItem(entityGrid.select());
return {
buildingId: selected.BuildingId
};
}
我的控制器方法定义为:
public JsonResult BuildingValidationLookups_Read([DataSourceRequest] DataSourceRequest request, int buildingId)
{
return Json(PopulateBuildingChangeValidationTypes(buildingId), JsonRequestBehavior.AllowGet);
}
一切都很顺利。