2016-10-04 42 views
0

我试图从一个编辑器模板转换,该模板用于在网格行的下拉列表中显示预定义的项目列表。这是有效的,但我需要为不同的网格定制列表,因为我的应用程序的不同区域之间的数据不一样。单元格中自定义dropdownlist的网格示例 - 它如何呈现下拉列表?

所以我看客户端模板和定义我自己的某种方式。

在这个例子中,我不知道在视图中使用“categories”列表的位置。
这个例子甚至用到了吗? 由于具有列表的“嵌套”属性,dropdownlist如何在行中呈现?

http://demos.telerik.com/aspnet-mvc/grid/editing-custom

private void PopulateCategories() 
{ 
    var dataContext = new SampleEntities(); 
    var categories = dataContext.Categories 
       .Select(c => new CategoryViewModel { 
        CategoryID = c.CategoryID, 
        CategoryName = c.CategoryName 
       }) 
       .OrderBy(e => e.CategoryName); 

    ViewData["categories"] = categories; 
    ViewData["defaultCategory"] = categories.First();    
} 

及其本行我想知道关于:
计算机[ “类别”] =类别;

这是为什么需要和使用它?我发现在控制器或视图中都没有使用它 - 除非读操作默认使用这种方法或某种类型的约定?

回答

1

ViewData["categories"]用于编辑器模板。此文件未显示在演示现场,但你可以看到它在脱机演示,你应该有从安装程序:

/Views/grid/EditorTemplates/ClientCategory.cshtml

这里是内容:

@model Kendo.Mvc.Examples.Models.CategoryViewModel 

@(Html.Kendo().DropDownListFor(m => m) 
    .DataValueField("CategoryID") 
    .DataTextField("CategoryName") 
    .BindTo((System.Collections.IEnumerable)ViewData["categories"]) 
) 

的更多信息在:

http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/templating/editor-templates

+2

如果您不想创建EditorTemplate,也可以使用网格的外键列功能:http://demos.telerik.com/aspnet-mvc/grid/foreignkeycolumn。 –

相关问题