2014-07-03 55 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定義爲:

​​

現在一切都很好。