2014-07-03 51 views
2

我有一个剑道格,而列定义:传递模型在剑道网格列ClientTemplate编辑

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

我想知道我如何将网格模型传递给客户端模板,以便下列行:

.BindTo((System.Collections.IEnumerable)Model.BuildingChangeValidationStatuses) 
) 

会正确解析。有任何想法吗?

+0

这可能没有帮助,但我的建议是使用foreignkey,因为它似乎是网格编辑模式下的下拉列表 – Roti

+0

Roti,不起作用。该列表是动态生成的。 – xgp

回答

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”,但也通过从检索到的数据“ getBuildingId” javascript函数,其定义为:

功能getBuildingId(){

var entityGrid = $("#BuildingValidationGrid").data("kendoGrid"); 
var selected = entityGrid.dataItem(entityGrid.select()); 
return { 
    buildingId: selected.BuildingId 
}; 

}

我的控制器我thod定义为:

​​

现在一切都很好。