gpt4 book ai didi

asp.net-mvc - 如何使用模型中的数据绑定(bind)为kendo数据源

转载 作者:行者123 更新时间:2023-12-01 19:23:19 24 4
gpt4 key购买 nike

我有一个空的 div,我想使用模型中的数据将其初始化为剑道网格。它应该类似于以下内容,但我无法加载数据

$("#mapsDiv").kendoGrid({
sortable: true,
dataSource: {
transport: {
read:"/Home/About",
dataType: "odata"
},
pageSize: 5
},
pageable: true,
resizable: true,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell"
});

关于.cshtml

@model List<KendoExample.Entities.ShortStudent>

<div class="row">
<div class="col-md-12 table-responsive" id="mapsDiv">
</div>

我的家庭 Controller 如下

List<ShortStudent> students = new List<ShortStudent>();

ShortStudent student1 = new ShortStudent();
student1.birthdate = new DateTime(1999, 4, 30);
student1.classname = "1B";
student1.firstname = "Fredie";
student1.surname = "Fletcher";
student1.studentid = 1;

ShortStudent student2 = new ShortStudent();
student2.birthdate = new DateTime(2010, 5, 4);
student2.classname = "1B";
student2.firstname = "Lee";
student2.surname = "Hobbs";
student2.studentid = 2;

students.Add(student1);
students.Add(student2);

return View(students);

我见过使用 json 但没有使用 odata 的示例...

此外,还有一些使用它的示例

@(Html.Kendo().Scheduler<MeetingViewModel>()
.Name("scheduler")
.Editable(false)
.DataSource(ds => ds
.Custom()
.Batch(true)
.Schema(schema => schema
.Model(m =>
{
m.Id(f => f.MeetingID);
m.Field("title", typeof(string)).DefaultValue("No title").From("Title");
m.Field("start", typeof(DateTime)).From("Start");
m.Field("end", typeof(DateTime)).From("End");
m.Field("description", typeof(string)).From("Description");
m.Field("recurrenceID", typeof(int)).From("RecurrenceID");
m.Field("recurrenceRule", typeof(string)).From("RecurrenceRule");
m.Field("recurrenceException", typeof(string)).From("RecurrenceException");
m.Field("isAllDay", typeof(bool)).From("IsAllDay");
m.Field("startTimezone", typeof(string)).From("StartTimezone");
m.Field("endTimezone", typeof(string)).From("EndTimezone");
}))
.Transport(new {
//the ClientHandlerDescriptor is a special type that allows code rendering as-is (not as a string)
read = new Kendo.Mvc.ClientHandlerDescriptor() {HandlerName = "customRead" }
})
)
)

我无法理解/实现,所以请忽略这种解决方案。

目前,我在屏幕上看到一个网格页脚,上面写着(4852 项中的 1 - 2 项),但没有任何标题或内容(数据行)。我做错了什么?

更新

  var dataSource = new kendo.data.DataSource(
{
transport: {
read: {
url: '@Url.Action("About", "Home")',
contentType: "application/json",
dataType: "json"
}
},
schema: {
model: {
fields: {
firstname: { type: "string" },
surname: { type: "string" },
birthdate: { type: "date" },
classname: { type: "string" }
}
}
},
type: "json",
serverPaging: false,
serverFiltering: true,
serverSorting: false
}
);

$("#mapsDiv")
.kendoGrid(
{

sortable: true,
dataSource: {

transport: {
read: dataSource
},
pageSize: 2
},
pageable: true,
resizable: false,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell",
columns:[{
field: "firstname",
},{
field: "surname",
},{
field: "classname",
},{
field: "age",
}]
});

家庭 Controller

 public ActionResult About()
{
....
return View(students);
}

现在带有标题的网格存在,但没有数据存在。如果我将操作更改为 json,它会在页面上返回纯 json

public ActionResult About()
{
....
return Json(students, JsonRequestBehavior.AllowGet);
}

最佳答案

您是否尝试过将字段添加到网格中?

$("#mapsDiv")
.kendoGrid(
{

sortable: true,
dataSource: {
transport: {
read:"/Home/About",
dataType: "odata"
},
pageSize: 5
},
columns: [
{
field: "classname",
title: "Class Name"
},
{
field: "firstname",
title: "First name"
},
{
field: "surname",
title: "Last name"
}
],
pageable: true,
resizable: true,
columnMenu: true,
scrollable:true,
navigatable: true,
editable: "incell"

});

关于asp.net-mvc - 如何使用模型中的数据绑定(bind)为kendo数据源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44171551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com