页面加载MVC后将数据绑定到网格

时间:2016-09-15 22:33:57

标签: asp.net-mvc kendo-grid

我在这里有问题。使用kendo网格我正在从控制器中的某个动作加载数据。但是在最后一列我有链接,它应该在同一个控制器中触发另一个动作。当我删除这段代码时

                     type: "json",
                   transport: {
                       read: {
                           url: "@Html.Raw(Url.Action("ListFinances", "Jobs"))",
                           type: "POST",
                           dataType: "json",
                           data: additionalData
                       },

                   },
                   schema: {
                       data: "Data",
                       total: "Total",
                       errors: "Errors"
                   },

最后一栏工作正常,位时存在这段代码,最后一栏不工作>请在这里帮助一下,我是mvc.Below的新代码:

                    $("#jobs-grid").kendoGrid({
                            dataSource: {
                                data: @Html.Raw(JsonConvert.SerializeObject(Model.FinishedJobs)),
                                schema: {
                                    model: {
                                        fields: {
                                            JobNumber: { type: "string" },
                                            CustomerId: { type: "number" },
                                            JobCount: { type: "number" },
                                            JobYear: { type: "number" },
                                            Status: { type: "number" },
                                            Position: { type: "number" },
                                            Finished: { type: "boolean" },
                                            HasInvoice: { type: "boolean" },
                                        }
                                    }
                                },
                                type: "json",
                   transport: {
                       read: {
                           url: "@Html.Raw(Url.Action("ListFinances", "Jobs"))",
                           type: "POST",
                           dataType: "json",
                           data: additionalData
                       },

                   },
                   schema: {
                       data: "Data",
                       total: "Total",
                       errors: "Errors"
                   },
                                error: function(e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                pageSize: 20,
                                serverPaging: true,
                                serverFiltering: true,
                                serverSorting: true
                            },

                            //dataBound: onDataBound,
                            columns: [
                                @*{
                                            field: "Status",
                                            title: "Status",
                                            template: '#= Status #'
                                        },*@
                                {
                                    field: "JobNumber",
                                    title: "jobNumber",
                                    template: '#= JobNumber #'
                                },
                                {
                                    field: "CustomerId",
                                    title: "Customer",
                                    template: '#= Customer.Name #'
                                },
                                {
                                    field: "Id",
                                    title: "Id"
                                },

                                @*{
                                            field: "ShortDesc",
                                            title: "ShortDesc"
                                        },*@
                                {
                                    field: "DateCompletition",
                                    title: "DateCompletition"
                                },
                                {
                                    field: "Id",
                                    title: "@T("Common.Edit")",
                                    width: 130,
                                    template: '<a href="../Finances/Edit/#=Id#">Edit</a>'
                                }
                            ],
                            pageable: {
                                refresh: true,
                                pageSizes: [5, 10, 20, 50]
                            },
                            editable: {
                                confirmation: false,
                                mode: "inline"
                            },
                            scrollable: false,
                            //  sortable: true,
                            //  navigatable: true,
                            //   filterable: true,
                            //  scrollable: true,
                            selectable: true

                        });
                    });
        </script>

1 个答案:

答案 0 :(得分:2)

似乎您想在网格中添加command,如here所述添加命令的方法如下

   var grid = $("#jobs-grid").kendoGrid({
                        dataSource: {
                           pageSize: 20,
                           data: @Html.Raw(JsonConvert.SerializeObject(Model.FinishedJobs)),
                        },
                        pageable: true,
                        height: 550,
                        columns: [
                            { field: "JobNumber", title: "JobNumber", width: "140px" },
                            { field: "CustomerId", title: "Customer", width: "140px" },
                            { field: "Id", title:"Id" },
                            { field: "DateCompletition", title:"DateCompletition" },
                            { command: { text: "Edit", 
                                         click: function(e){
                                              // here you can add your code
                                          }}, 
                              title: " ", 
                              width: "180px" }]
                    }).data("kendoGrid");

您可以查看剑道网格here

的文档

希望这会对你有所帮助