Skip to main content
 首页 » 编程设计

c#之kendo Grid 中的可空枚举属性

2024年02月05日10www_RR

我有几个枚举属性,我想将它们绑定(bind)到网格。我正在使用以下代码

column.ForeignKey(p => p.<EnumpropertyName>,  
Model.<EnumList_As_SelectedItemList>, "Value", "Text"); 

EnumpropertyName 是可为空的枚举。

在另一列中,我指的是属性的子属性

column.ForeignKey(p => p.<Enumproperty2Name>.<childProperyName>,  
Model.<AnotherEnumList_As_SelectedItemList>, "Value", "Text"); 

childProperyName 是可为空的枚举。

因为这是我拥有的子对象内部

.Model(model => 
 { 
    model.Id(p => p.InfoTableId); 
    model.Field(p => p.<Enumproperty2Name>).DefaultValue(new      Enumproperty2Name()); 
  }) 

这是行不通的,因为我添加了新行并为这些下拉列表选择了值,选择后值丢失了。但是,如果我删除 nullable 并让它们成为常规枚举属性,它们就可以工作。

如何使可空枚举在剑道网格中工作。

谢谢

请您参考如下方法:

要在 Kendo Grid 中添加下拉菜单,请尝试以下操作。

columns.ForeignKey(p => p.ExamDateStatus, (System.Collections.IEnumerable)ViewData["ExamStatus"], "Value", "Text") 
.Title("Status").EditorTemplateName("ComboForeignKey").Width(100);  

“ComboForeignKey”是一个局部 View ,位于 Views\Shared\EditorTemplates 文件夹中。它的内容必须类似于以下内容。

@model object 
 
@( 
 Html.Kendo().DropDownListFor(m => m).OptionLabel("Select Below...") 
 .HtmlAttributes(new { data_value_primitive = "true"}) 
 .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"]) 
)