asp.net mvc-KendoUI网格.一列中有多个值



我正在使用Razor和KendoUI开发一个ASP.NET MVC 4.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.Name|具有Rol.Description|具有Rol.Active的列|具有所有Rol.Permissions.Name(列表)的列

并监视KendoUI 的CRUD操作

在我看来:

@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"))
            )
    )

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

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

然后,这个属性可以调用Permissions并转换为一个列出Names的字符串。不要试图在网格中做这件事,在你的Rol课堂上做。我还建议将Rol重命名为RoleModel,将Permission重命名为PermissionModel,但显然这是首选。

相关内容

最新更新