弹出窗口中的Kendo grid外键列为下拉列表

时间:2016-04-14 05:42:08

标签: asp.net-mvc-4 kendo-ui kendo-grid

我有三个表tbl_admin_group,tbl_admin_role,tbl_admin_groupRole组的主键和角色是grouprole中的外键。  现在我有一个表单,我想先在dropdownlist中显示外键 对于tbl_admin_role。图片链接如下 控制器操作方法

 public ActionResult GetGroupRole()
    {

        dbcontext.Configuration.ProxyCreationEnabled = false;
        List<TBL_ADMIN_GROUP_ROLE> lst = dbcontext.TBL_ADMIN_GROUP_ROLE.Where(x => x.IsDeleted == 0).ToList();
also try this
 //List<TBL_ADMIN_GROUP_ROLE> lst = dbcontext.TBL_ADMIN_GROUP_ROLE.Include(r => r.TBL_ADMIN_ROLE).Include(g => g.TBL_ADMIN_GROUP).ToList();
        ViewData["rolesList"] = lst;
        return View(lst);

    }

Razor视图

 @(Html.Kendo().Grid<TBL_ADMIN_GROUP_ROLE>().Name("Grid")

                .Columns(columns =>
                {
                    columns.Template(t => { }).Title("S.No").ClientTemplate("#= renderNumber(data) #");

                    columns.ForeignKey(p => p.RoleID, (System.Collections.IEnumerable)ViewData["rolesList"], "RoleID", "RoleName")
                        .Title("Role").Width(200).EditorTemplateName("RolesDropDown");
                    columns.Bound(gp => gp.GroupID).Width(200).Title("Group ID");

                    columns.Command(command => { command.Edit(); command.Destroy(); }).Title("Actions");
                })
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .PageSize(10)
                        .Model(model => model.Id(gp => gp.GroupRoleID))
                                                                .Read(read => read.Action("GroupRole_Read", "Security"))
                        .Update(up => up.Action("UpdateGroupRole", "Security"))
                        .Destroy(update => update.Action("DeleteGroupRole", "Security")))
                        .Pageable(pageable => pageable
                                    .PageSizes(true)
                                    .ButtonCount(5))
                        .Selectable()
                        .Sortable()
                        .Editable(ed => ed.Mode(GridEditMode.PopUp).TemplateName("Update Group Role"))
                                  .Events(e => e.Edit("onEdit"))
                                          .Events(ev => ev.DataBound("resetRowNumber"))                                
            )

我也尝试使用编辑器模板但失败了。请帮我 。提前谢谢。

编辑模板

 @model int
    @(Html.Kendo().DropDownListFor(m => m)
            .AutoBind(false)
            .OptionLabel("Select Role...")
            .DataTextField("RoleName")
            .DataValueField("RoleID")
            .DataSource(dataSource =>
            {
                dataSource.Read(read => read.Action("GetRoles", "Security"))
                        .ServerFiltering(true);
            })
    )

enter image description here

0 个答案:

没有答案