2011-05-05 51 views
0

我正在研究網格需要顯示ICD描述以及與其相關的HCC類別描述的醫療應用。該ICD和HCC類型是這樣的:具有相同屬性名稱的Telerik網格

public class ICD { 
    public String Code { get; set; } 

    public String Description { get; set; } 

    public HCC HCC { get; set; } 
} 

public class HCC { 
    public Int32 ID { get; set; } 

    public String Description { get; set; } 
} 

當我綁定Telerik的MVC擴展電網ICD對象的列表,我設置了像這樣的列:

this.Html.Telerik().Grid(this.Model.ICDs) 
    .Name("ICDGrid") 
    .DataKeys(keys => keys.Add(icd => icd.Code)) 
    .DataBinding(binding => { 
     binding.Ajax().Select(this.Model.AjaxSelectMethod); 
     binding.Ajax().Update(this.Model.AjaxUpdateMethod); 
    }) 
    .Columns(columns => { 
     columns.Bound(icd => icd.ICDType.Name).Title("ICD 9/10"); 
     columns.Bound(icd => icd.Code); 
     columns.Bound(icd => icd.Description); 
     columns.Bound(icd => icd.HCC.Description).Title("HCC Category") 
     columns.Command(commands => commands.Delete()).Title("Actions").Width(90); 
    }) 
    .Editable(editing => editing.Mode(GridEditMode.InCell).DefaultDataItem(new ICD())) 
    .ToolBar(commands => { 
     commands.Insert(); 
     commands.SubmitChanges(); 
    }) 
    .Sortable() 
    .Filterable() 
    .Pageable(paging => paging.PageSize(12)) 
    .Render(); 

問題ICD和HCC都具有名爲「描述」的屬性,我無法控制這一點。有沒有辦法告訴Telerik在它生成的JavaScript中稱他們爲不同的東西?像ICDDescription和HCCDescription?

回答

1

當前您不能別名屬性。你可以做的是創建一個ViewModel對象,其中的屬性被唯一命名。然後將網格綁定到ViewModel對象。下面的代碼片段:

public class ICDViewModel 
{ 
    public string Description 
    { 
     get; 
     set; 
    } 
    public string HCCDescription 
    { 
     get; 
     set; 
    } 
    // The rest of the properties of the original ICD class 
} 

然後,你需要改變Model.ICDs使用ICDViewModel的類型。您可以使用Select擴展方法ICD映射到ICDViewModel:

Model.ICDs = icds.Select(icd => new ICDViewModel 
{ 
    Description = icd.Description, 
    HCCDescription = icd.HCC.Description 
    /* set the rest of the ICD properties */ 
}); 
+0

是的,我已經有點想避免爲ICD和HCC類是已經是一個視圖模型的一部分。噢,不能擁有一切。感謝您的回答! – Yuck 2011-05-06 11:36:06

相關問題