使用Kendo UI Grid,如何创建一个自定义工具栏,其中包含一个链接回控制器中的Action的按钮?

时间:2014-10-27 16:57:43

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

以下是我的代码。我需要将onclick链接到我的控制器中的Action,用于工具栏按钮。

<script>
                    $(document).ready(function() {
                        var grid = $("#grid").kendoGrid({
                            dataSource: {
                                      transport: {
                                          read: { url: '@Url.Action("GetCars", "Home")' }
                                pageSize: 20,
                                serverPaging: true,
                                serverSorting: true,
                                serverFiltering: true
                            },
                            toolbar: [ { name: "create", text: "Add a new car" }],
                            height: 550,
                            sortable: true,
                            pageable: true,
                            columns: [
                                { field: "ProductID", title: "Product ID", width: 100 },
                                { field: "ProductName", title: "Product Name" },
                                { field: "UnitPrice", title: "Unit Price", width: 150 },
                                { field: "QuantityPerUnit", title: "Quantity Per Unit" }
                            ]
                        });
    </script>

我总是在剃刀中做到的方式是:

.ToolBar(toolbar => toolbar.Custom().Text("Add new car").Action("Create", "Home"))    

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。

toolbar: [{ name:"create", template: "<input type='submit' value='Add
      new' onclick=\"location.href='@Url.Action("Create", "Home")'\" />" }],