从kendo网格的webservice方法获取数据

时间:2017-07-08 10:45:15

标签: c# asp.net json web-services kendo-grid

我想从webservice方法获取数据并填充我的kendo网格。

我的方法运行并获取数据但是当填充kendo网格显示此错误时: https://image.ibb.co/jNJB4a/asfasfas.png

我在web方法中的代码:

[System.Web.Services.WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]//Specify return format. 
public string TierPriceListWithProduct(string ID)
{
    BOProduct boProduct = new BOProduct();
    boProduct.Id = Convert.ToInt32(ID);
    string Result = "";
    if (boProduct != null)
    {
        try
        {
            IList<DAOTierPrice> daoTierPriceCollection = DAOTierPrice.SelectAllByProductId(boProduct.Id);
            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            string result = serializer.Serialize(daoTierPriceCollection);
            Result = result;
        }
        catch (Exception ex)
        {
            Result = "Faild#SystemError#reson#" + ex.Message;
        }
    }
    return Result;
}

来自客户的代码:

$(document).ready(function () {
var ID = getUrlVars()["ID"];
var BOProduct = {};
BOProduct.Id = ID;
var data = JSON.stringify(BOProduct);
//AjaxFunctionsAdminPages.asmx / TierPriceListWithProduct",
$("#tierprices-grid").kendoGrid({
    dataSource: {
        type: "json",
        transport: {
            read: {
                url: "../../AjaxFunctionsAdminPages.asmx/TierPriceListWithProduct",
                type: "POST",
                dataType: "json",
                data: {
                    ID: ID
                }
            },
            destroy: {
                url: "/Admin/Product/TierPriceDelete",
                type: "POST",
                dataType: "json",
                data: addAntiForgeryToken
            }
        },
        schema: {
            data: "Data",
            total: "Total",
            errors: "Errors",
            model: {
                id: "Id",
                fields: {
                    Store: { editable: true, type: "string" },
                    StoreId: { editable: true, type: "number" },
                    CustomerRole: { editable: true, type: "string" },
                    CustomerRoleId: { editable: true, type: "number" },
                    Quantity: { editable: true, type: "number" },
                    Price: { editable: true, type: "number" },
                    StartDateTimeUtc: { editable: true, type: "date" },
                    EndDateTimeUtc: { editable: true, type: "date" },
                    Id: { editable: false, type: "number" }
                }
            }
        },
        error: function (e) {
            display_kendoui_grid_error(e);
            // Cancel the changes
            this.cancelChanges();
        }
    },
    pageable: {
        refresh: true,
        numeric: false,
        previousNext: false,
        info: false
    },
    editable: {
        confirmation: "hhhhhh",
        mode: "inline"
    },
    scrollable: false,
    columns: [
        {
            field: "StoreId",
            hidden: true,
            title: "Store",
            template: "#:Store#"
        }, {
            field: "CustomerRoleId",
            title: "Customer",
            template: "#:CustomerRole#"
        }, {
            field: "Quantity",
            title: "Quantity",
            format: "{0:0}"
        }, {
            field: "Price",
            title: "Price"
        }, {
            field: "StartDateTimeUtc",
            title: "astartdatetimeutc",
            type: "date",
            format: "{0:G}"
        }, {
            field: "EndDateTimeUtc",
            title: "enddatetimeutc",
            type: "date",
            format: "{0:G}"
        }, {
            field: "Id",
            title: "Edit",
            headerAttributes: { style: "text-align:center" },
            attributes: { style: "text-align:center" },
            template: "<button onclick=\"javascript:OpenWindow('/Admin/Product/TierPriceEditPopup/#=Id#?btnId=btnRefreshTierPrices&formId=product-form', 800, 600, true); return false;\" class='btn btn-default'><i class='fa fa-pencil'></i>Edit</button>"
        }, {
            command: { name: "destroy", text: "Delete" },
            title: "Delete"
        }
    ]
});

});

0 个答案:

没有答案