Asp.net mvc 肯杜伊网格。列中有多个值

Asp.net mvc 肯杜伊网格。列中有多个值,asp.net-mvc,kendo-ui,kendo-grid,razor-2,Asp.net Mvc,Kendo Ui,Kendo Grid,Razor 2,我正在用Razor和KendoUI开发一个ASP.NETMVC4.5项目。我有以下两门课: public class Rol { [Key] [ScaffoldColumn(false)] public int RolId { get; set; } [Required] [MaxLength(50)] public string Name{ get; set; } [Ma

我正在用Razor和KendoUI开发一个ASP.NETMVC4.5项目。我有以下两门课:

public class Rol
    {
        [Key]
        [ScaffoldColumn(false)]
        public int RolId { get; set; }

        [Required]
        [MaxLength(50)]
        public string Name{ get; set; }

        [MaxLength(255)]
        public string Desciption { get; set; }

        public bool Active{ get; set; }

        [DisplayName("Permissions")]
        public virtual ICollection<Permission> Permissions { get; set; }
    }

public class Permission
    {
        [Key]
        [ScaffoldColumn(false)]
        public int PermisoId { get; set; }

        [Required]
        [MaxLength(50)]
        public string Name { get; set; }

        [MaxLength(255)]
        public string Description { get; set; }

        public bool Active { get; set; }

        public ICollection<Rol> Rols { get; set; }
    }
公共类Rol
{
[关键]
[脚手架立柱(假)]
公共int RolId{get;set;}
[必需]
[MaxLength(50)]
公共字符串名称{get;set;}
[最大长度(255)]
公共字符串说明{get;set;}
公共bool活动{get;set;}
[显示名称(“权限”)]
公共虚拟ICollection权限{get;set;}
}
公共类许可
{
[关键]
[脚手架立柱(假)]
公共int PermisoId{get;set;}
[必需]
[MaxLength(50)]
公共字符串名称{get;set;}
[最大长度(255)]
公共字符串说明{get;set;}
公共bool活动{get;set;}
公共ICollection Rols{get;set;}
}
但我不知道如何制作具有列的网格:

具有Rol.Name的列|具有Rol.Description的列|具有Rol.Active的列|具有所有Rol.Permissions.Name的列(列表)

支持KendoUI的积垢作业

我认为:

@model IEnumerable<ItemsMVC.Models.Rol>    
    @(
        Html.Kendo().Grid(Model)
            .Name("Grid")
            .Columns(c =>
                {
                    c.Bound(p => p.RolId).Visible(false);
                    c.Bound(p => p.Name);
                    c.Bound(p => p.Description);
                    c.Bound(p => p.Active)
                        .ClientTemplate("#= Active ? 'yes' : 'No' #")
                        .Width(100);
                    **HERE THE LIST OF PERMISSIONS**
                    c.Command(p => { 
                        p.Edit(); 
                        p.Destroy();
                    }).Width(200);
                }        
            )        
            .Pageable(p => p.Enabled(true))
            .Scrollable(s => s.Enabled(true))
            .Sortable(s => s.Enabled(true))
            .Filterable(f => f.Enabled(true))
            .ColumnMenu(c => c.Enabled(true))
            .ToolBar(t => t.Create())
            .Editable(e => e.Mode(GridEditMode.PopUp))
            .DataSource( ds => ds
                .Ajax()
                .Model(model =>model.Id(p => p.RolId))
                .Create(c => c.Action("EditingInline_Create", "Rol"))
                .Read(r => r.Action("Permisos_Read","Rol"))
                .Update(u => u.Action("EditingInline_Update", "Rol"))
                .Destroy(d => d.Action("EditingInline_Destroy", "Rol"))
            )
    )
@model IEnumerable
@(
Html.Kendo().Grid(模型)
.名称(“网格”)
.列(c=>
{
c、 绑定(p=>p.RolId)。可见(false);
c、 绑定(p=>p.Name);
c、 界限(p=>p.Description);
c、 绑定(p=>p.Active)
.ClientTemplate(“#=活动?'yes':'No'#”)
.宽度(100);
**这里是权限列表**
c、 命令(p=>{
p、 编辑();
p、 破坏();
}).宽度(200);
}        
)        
.Pageable(p=>p.Enabled(true))
.Scrollable(s=>s.Enabled(true))
.Sortable(s=>s.Enabled(true))
.Filterable(f=>f.Enabled(true))
.column菜单(c=>c.Enabled(true))
.ToolBar(t=>t.Create())
.Editable(e=>e.Mode(GridEditMode.PopUp))
.DataSource(ds=>ds
.Ajax()
.Model(Model=>Model.Id(p=>p.RolId))
.Create(c=>c.Action(“编辑行”\u Create,“Rol”))
.Read(r=>r.Action(“Permisos_Read”,“Rol”))
.Update(u=>u.Action(“编辑行更新”、“Rol”))
.Destroy(d=>d.Action(“编辑行”\u Destroy,“Rol”))
)
)

您需要在Rol中创建另一个名为

string PermissionList
{
    get ( return [Convert Permissions collection to string of values]; ) 
}

然后,该属性可以调用权限并转换为列出名称的字符串。不要试图在网格中这样做,而是在Rol类中这样做。我还建议将Rol重命名为RoleModel,将PermissionModel重命名为PermissionModel,但显然这是首选项。

使用ClientTemplate在列中组合多个字段。