Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 剑道UI网格基本实现_Asp.net_Asp.net Mvc 4_Kendo Ui_Kendo Grid - Fatal编程技术网

Asp.net 剑道UI网格基本实现

Asp.net 剑道UI网格基本实现,asp.net,asp.net-mvc-4,kendo-ui,kendo-grid,Asp.net,Asp.net Mvc 4,Kendo Ui,Kendo Grid,我试图实现网格的基本功能,在编译我的项目时,我得到一个错误,上面写着“预期对象” 使用以下代码行: $(document).ready(function() { $("#grid").kendoGrid({ dataSource: { data: createRandomData(50), //exception in this line of code

我试图实现网格的基本功能,在编译我的项目时,我得到一个错误,上面写着“预期对象”

使用以下代码行:

         $(document).ready(function() {
                $("#grid").kendoGrid({
                    dataSource: {
                        data: createRandomData(50),  //exception in this line of code
                        pageSize: 10
                    },
你们能帮助我理解我需要写什么来代替createRandomData吗? 它是我将数据放在网格上的表名还是其他名称?(顺便说一句,我正在使用as SQL server 2008作为后端,并在Visual Studio 2010 MVC4上运行此代码),我对MVC和剑道UI也是新手

我试图实现的是使用MVC4将数据从SQLServer绑定到网格

提前感谢!:)

代码如下:

              <script>
            $(document).ready(function () {
                $("#grid").kendoGrid({
                    dataSource: {
                        data: createRandomData(50),
                        pageSize: 10
                    },
                    groupable: true,
                    sortable: true,
                    pageable: {
                        refresh: true,
                        pageSizes: true
                    },
                    columns: [{
                        field: "FirstName",
                        width: 90,
                        title: "First Name"
                    }, {
                        field: "LastName",
                        width: 90,
                        title: "Last Name"
                    }, {
                        width: 100,
                        field: "City"
                    }, {
                        field: "Title"
                    }, {
                        field: "BirthDate",
                        title: "Birth Date",
                        template: '#= kendo.toString(BirthDate,"dd MMMM yyyy") #'
                    }, {
                        width: 50,
                        field: "Age"
                    }
                    ]
                });
            });
        </script>

函数createRandomData(50)应该返回一个json对象。请同时显示函数定义


网格中的列名与返回的json对象不匹配

文档中有很多ASP.NET教程。我建议你先开始。如果您不熟悉从服务器返回JSON,还有一些教程。

在服务器端,使用必要的属性定义一个类型。然后使用数据库中的服务器端代码或使用一些随机数据填充对象数组。从控制器使用内置JavaScript序列化程序将数组序列化为JSON并作为JsonResult返回。比如说,

公共JsonResult CreateRandomData(整数计数){

名单人员=

返回新的JsonResult(){Data=persons,ContentType=“application/json”,JsonRequestBehavior=JsonRequestBehavior.AllowGet}

}


内置JsonSerializer(System.Web.Mvc)提供JSON序列化和反序列化支持。

您正在传递对象,不是吗。。尝试将该数据对象转换为json
    function createRandomData(count) {
       var data = [],
      now = new Date();
       for (var i = 0; i < count; i++) {
        var firstName = firstNames[Math.floor(Math.random() * firstNames.length)],
        lastName = lastNames[Math.floor(Math.random() * lastNames.length)],
        city = cities[Math.floor(Math.random() * cities.length)],
        title = titles[Math.floor(Math.random() * titles.length)],
        birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
        age = now.getFullYear() - birthDate.getFullYear();

    data.push({
        Id: i + 1,
        FirstName: firstName,
        LastName: lastName,
        City: city,
        Title: title,
        BirthDate: birthDate,
        Age: age
    });
}
return data;
    public ActionResult createRandomData()
    {
       return View();
    }