Kendo网格工具栏的多次重载?

时间:2015-01-28 18:24:37

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

我试图配置一个Kendo网格工具栏来让Kendo"创建"网格内的功能,以及位于其中的自定义按钮。以下是我到目前为止的情况:

   @(Html.Kendo().Grid<VIEWMODELHERE>()
            .Name("UserProfileGrid")
            .Resizable(c => c.Columns(true))
            .Selectable()
            .Filterable()
            .Groupable()
            .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("UserCreateTemplate"))

            .ToolBar(x => x.Create(), x.Template(@<text>

                    @(Html.Kendo().Button()
                    .Name("ButtonAddUser")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("downloads")
                    .Content("Add User")
                    .Events(e => e.Click("createUser")))

                    @(Html.Kendo().Button()
                    .Name("ButtonEditUser")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("settings")
                    .Content("Edit User")
                    .Events(e => e.Click("Edituser")))

                    @(Html.Kendo().Button()
                    .Name("ButtonRefreshPage")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("history")
                    .Content("Refresh Page")
                    .Events(e => e.Click("RefreshPage")))

                    @(Html.Kendo().Button()
                    .Name("ButtonDeleteUser")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("history")
                    .Content("Delete a user")
                    .Events(e => e.Click("DeleteUser")))

                    @(Html.Kendo().Button()
                    .Name("ButtonAbout")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("history")
                    .Content("About")
                    .Events(e => e.Click("aboutButtonClick")))
            </text>)));

问题是我似乎无法使用lambda函数正确创建按钮,因为它没有正确读取create函数。

2 个答案:

答案 0 :(得分:5)

如您所知,您有语法问题。由于您在工具栏命令(x.Create和x.Template)中使用了多个命令,因此需要通过将主体包装在“{}”中将其转换为块。在x.Create()之后变为“;”结束这条线。

.ToolBar(x =>
{
    x.Create();
    x.Template(@<text>

        @(Html.Kendo().Button()
    .Name("ButtonAddUser")
    .HtmlAttributes(new { type = "k-button" })
    .Icon("downloads")
    .Content("Add User")
    .Events(e => e.Click("createUser")))
    </text>);
})

答案 1 :(得分:2)

Prashant你是对的!对于遇到此问题的未来用户,您可以轻松完成此操作:

<a class='k-button k-grid-add' href='#'>Add new User</a>

所以我现在有:

  toolbar.Template(@<text>


                    <a class='k-button k-grid-add' href='#'>Add new User</a>

                    @(Html.Kendo().Button()
                    .Name("ButtonEditUser")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("settings")
                    .Content("Edit User")
                    .Events(x => x.Click("Edituser")))

                        @(Html.Kendo().Button()
                    .Name("ButtonRefreshPage")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("history")
                    .Content("Refresh Page")
                    .Events(x => x.Click("RefreshPage")))

                        @(Html.Kendo().Button()
                    .Name("ButtonDeleteUser")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("history")
                    .Content("Delete a user")
                    .Events(x => x.Click("DeleteUser")))

                        @(Html.Kendo().Button()
                    .Name("ButtonAbout")
                    .HtmlAttributes(new { type = "k-button" })
                    .Icon("history")
                    .Content("About")
                    .Events(x => x.Click("aboutButtonClick")))
                    </text>);})

也许不漂亮,razer和html的混合......但它适用于我们的敏捷环境。