C# 如何使用剑道UI传输方法?

C# 如何使用剑道UI传输方法?,c#,asp.net,json,kendo-ui,kendo-grid,C#,Asp.net,Json,Kendo Ui,Kendo Grid,在这里,我列出了一个JSON数组,并返回了国家的名称成功剑道网格显示编辑选项,但没有显示检索到的值 [WebMethod(EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)] public string coutryNames() { List<Diction

在这里,我列出了一个JSON数组,并返回了国家的名称成功剑道网格显示编辑选项,但没有显示检索到的值

 [WebMethod(EnableSession = true)]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
    public string coutryNames()
    {
        List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
        Dictionary<string, string> udemy = new Dictionary<string, string>();
        udemy.Add("92", "Pakistan");
        udemy.Add("91", "India");
        udemy.Add("90", "Afghanistan");
        udemy.Add("82", "Russia");
        udemy.Add("41", "China");
        udemy.Add("40", "Japan");
        udemy.Add("21", "UAE");
        udemy.Add("51", "Srilanka");
        list.Add(udemy);
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Serialize(list);

    }
我想的主要问题是模式和模型,让我们看看:

   schema: {

                model: {
                    id: "id",
                    fields: {
                        id: { editable: true, nullable: true },
                        name: { validation: { required: true } }
                    }

                }
剑道格网的显示方式如下:

    $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: true,
            filterable: true,
            height: 400,
            toolbar: ["create"],
            columns: [
                      { field: "id", title: "Identification" },
                      { field: "name", title: "Country Name" },
                      { command: ["edit", "destroy"], title: "&nbsp;", width: "160px" }
            ],
            editable: "popup"
        });
    });
测试期间,JSON数据采用以下格式:

 <string xmlns="http://tempuri.org/"> 
 [{"92":"Pakistan","91":"India","90":"Afghanistan","82":"Russia","41":"China","40":"Japan","21":"UAE","51":"Srilanka"}]

[{“92”:“巴基斯坦”、“91”:“印度”、“90”:“阿富汗”、“82”:“俄罗斯”、“41”:“中国”、“40”:“日本”、“21”:“阿联酋”、“51”:“斯里兰卡”}]


如何在剑道格网中查看此内容?

创建一个类,
Country

public Country 
{
  public int Id {get; set;}  
  public string Name {get; set;}
}
public string coutryNames()
    {
        List<Country> list = new List<Country>();
        List.Add(new Country {Id = 92, Name = "Pakistan"});
        //etc
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Serialize(list);
    }
然后,创建一个
国家的集合

public Country 
{
  public int Id {get; set;}  
  public string Name {get; set;}
}
public string coutryNames()
    {
        List<Country> list = new List<Country>();
        List.Add(new Country {Id = 92, Name = "Pakistan"});
        //etc
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        return serializer.Serialize(list);
    }
公共字符串coutryNames()
{
列表=新列表();
添加(新国家{Id=92,Name=“巴基斯坦”});
//等
JavaScriptSerializer serializer=新的JavaScriptSerializer();
返回序列化程序。序列化(列表);
}

然后,您应该能够绑定到它,因为
JSON
对象将具有与剑道字段匹配的属性。

这里是一个完整的解决方案

 document.onreadystatechange = function () {



var viewModel = kendo.observable({

    products: new kendo.data.DataSource({


        transport: {

            read: {
                type: "GET",
                url: "/api/Companies/GetAllCompanies2",
                dataType: "json"
            },

            create: {

                 type: "PUT",
                    url: "/api/Companies/UpdateDefCompny",
                  contentType: "application/json; charset=utf-8",
                    dataType: "json",
                async: false

            },
            update: {
                url:"/api/Companies/SaveDefCompny",
                async: false,
                contentType: "application/json",
                dataType: "json",
                type: "POST"
                 // here you need correct api url

            },
            destroy: {
                url: "/api/Companies/Delete", // here you need correct api url
                dataType: "json"
            },


            parameterMap: function (data, operation) {
                if (operation !== "read" && data) {
                    return JSON.stringify(data.models[0]);
                }
            }
        },
        serverPaging: true,
        serverFiltering: true,
        pageSize: 10,
        schema: {
            //data:"Data",
            total: "Count",

            model: {
                id: "Id",
                fields: {
                    Id: { type: "int" },
                    CurrentCurrencyCode: { editable: true, type: "int" },
                    ShortName: { editable: true, type: "string" },
                    FullName: { editable: true, type: "string" },
                    ContactPerson: { editable: true, type: "string" },
                    Address1: { editable: true, type: "string" },
                    CompanyCity: { editable: true, type: "string" },
                    CompanyState: { editable: true, type: "string" },
                    CompanyCountry: { editable: true, type: "string" },
                    ZipPostCode: { editable: true, type: "string" },
                    TelArea: { editable: true, type: "string" }

                }
            }
        },
        batch: true,


    }) 


  });


       kendo.bind(document.getElementById("example"), viewModel);


      }