C# Telerik kendo ui mvc dropdownlist在编辑模式下以网格显示,在显示模式下显示值
所以我有一个剑道UI网格 我有一列是int 基本上有一个int列和 1意味着好, 2意味着最好, 3表示最高 使用枚举是正确的,但我不能(内部业务规则) 所以我需要做一个自定义下拉列表来替换这个数字 在mvc中有两种方法可以做到这一点 一种是使用EditorTemplateName 另一种是使用外键 问题是EditorTemplateName仅在编辑模式下工作,并在显示模式下显示数字,C# Telerik kendo ui mvc dropdownlist在编辑模式下以网格显示,在显示模式下显示值,c#,asp.net-mvc-5,telerik,telerik-grid,telerik-mvc,C#,Asp.net Mvc 5,Telerik,Telerik Grid,Telerik Mvc,所以我有一个剑道UI网格 我有一列是int 基本上有一个int列和 1意味着好, 2意味着最好, 3表示最高 使用枚举是正确的,但我不能(内部业务规则) 所以我需要做一个自定义下拉列表来替换这个数字 在mvc中有两种方法可以做到这一点 一种是使用EditorTemplateName 另一种是使用外键 问题是EditorTemplateName仅在编辑模式下工作,并在显示模式下显示数字, ForeignKey只在显示模式下工作,并在编辑模式下显示数字经过一些艰苦的工作后,确定了我的想法 我使用了C
ForeignKey只在显示模式下工作,并在编辑模式下显示数字经过一些艰苦的工作后,确定了我的想法 我使用了ClientTemplate和EditorTemplateName
columns.Bound(c => c.Condition)
.EditorTemplateName("_ConditionDropDown")
.ClientTemplate("# if (Condition=== 1) {#" +
"good" +
"#} else if (Condition=== 2) {#" +
"best" +
"#} else if (Condition=== 3) {#" +
"top" +
"#}#");
它可以根据我的需要工作
我决定添加我使用的模板,它可能会帮助别人
@{
ViewBag.ConditionDropDownList = new List<SelectListItem>()
{
new SelectListItem { Value="0", Text="- All Conditions -" },
new SelectListItem { Value="1", Text="good" },
new SelectListItem { Value="2", Text="best" },
new SelectListItem { Value="3", Text="top" }
};
}
@(Html.Kendo().DropDownList()
.Name("Condition")
.DataTextField("Text")
.DataValueField("Value")
.BindTo((System.Collections.IEnumerable)ViewBag.ConditionDropDownList)
.Value("0")
)
@{
ViewBag.ConditionDropDownList=新列表()
{
新建SelectListItem{Value=“0”,Text=“-All-Conditions-”,
新建SelectListItem{Value=“1”,Text=“good”},
新建SelectListItem{Value=“2”,Text=“best”},
新建SelectListItem{Value=“3”,Text=“top”}
};
}
@(Html.Kendo().DropDownList())
.名称(“条件”)
.DataTextField(“文本”)
.DataValueField(“值”)
.BindTo((System.Collections.IEnumerable)ViewBag.ConditionDropDownList)
.价值(“0”)
)
经过一些艰苦的工作,我终于想到了这一点
我使用了ClientTemplate和EditorTemplateName
columns.Bound(c => c.Condition)
.EditorTemplateName("_ConditionDropDown")
.ClientTemplate("# if (Condition=== 1) {#" +
"good" +
"#} else if (Condition=== 2) {#" +
"best" +
"#} else if (Condition=== 3) {#" +
"top" +
"#}#");
它可以根据我的需要工作
我决定添加我使用的模板,它可能会帮助别人
@{
ViewBag.ConditionDropDownList = new List<SelectListItem>()
{
new SelectListItem { Value="0", Text="- All Conditions -" },
new SelectListItem { Value="1", Text="good" },
new SelectListItem { Value="2", Text="best" },
new SelectListItem { Value="3", Text="top" }
};
}
@(Html.Kendo().DropDownList()
.Name("Condition")
.DataTextField("Text")
.DataValueField("Value")
.BindTo((System.Collections.IEnumerable)ViewBag.ConditionDropDownList)
.Value("0")
)
@{
ViewBag.ConditionDropDownList=新列表()
{
新建SelectListItem{Value=“0”,Text=“-All-Conditions-”,
新建SelectListItem{Value=“1”,Text=“good”},
新建SelectListItem{Value=“2”,Text=“best”},
新建SelectListItem{Value=“3”,Text=“top”}
};
}
@(Html.Kendo().DropDownList())
.名称(“条件”)
.DataTextField(“文本”)
.DataValueField(“值”)
.BindTo((System.Collections.IEnumerable)ViewBag.ConditionDropDownList)
.价值(“0”)
)
这种方法有时会起作用,如果不起作用,第二个答案也会起作用
默认情况下,foreignkey列应使用dropdownlist。如果项目中未使用dropdownlist,则表示EditorTemplates文件夹中缺少GridForeignKey编辑器模板。如果是这种情况,您应该将编辑器从[Installation folder]>wrappers>aspnetmvc>EditorTemplates>razor文件夹复制到项目中的EditorTemplates文件夹中。这种方法有时会起作用,如果不是,第二个答案会起作用
默认情况下,foreignkey列应使用dropdownlist。如果项目中未使用dropdownlist,则表示EditorTemplates文件夹中缺少GridForeignKey编辑器模板。如果是这种情况,您应该将编辑器从[Installation folder]>wrappers>aspnetmvc>EditorTemplates>razor文件夹复制到项目中的EditorTemplates文件夹。您看到了吗?好的,我看到他正在使用一个ClientTemplate,但是当我制作ClientTemplate.ClientTemplate(“#:Text#”);单元格中的文本显示“function Text(){[native code]}”时,你看到了吗?好的,我看到他正在使用一个ClientTemplate,但是当我制作ClientTemplate.ClientTemplate(“#:Text#”);单元格中的文本显示“function Text(){[本机代码]}”