0

我正在开发一个网格需要显示 ICD 描述及其相关 HCC 类别描述的医疗应用程序。ICD 和 HCC 类型如下所示:

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 这样的东西?

4

1 回答 1

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 */
});
于 2011-05-06T07:50:16.030 回答