Kendo ui 使用实体框架将KendoUI绑定到Sql数据
我正在用实体框架开发一个Asp.net MVC3应用程序。我将Knockoutjs用于绑定,将KendoUI用于视图的UI部分。我能够实现大多数KendoUi小部件,但现在我需要使用KendoUi网格控件,它从SQL server获取数据。据我所知,网格小部件使用XML或JSON 所以我有一个db上下文:Kendo ui 使用实体框架将KendoUI绑定到Sql数据,kendo-ui,asp.net-mvc,Kendo Ui,Asp.net Mvc,我正在用实体框架开发一个Asp.net MVC3应用程序。我将Knockoutjs用于绑定,将KendoUI用于视图的UI部分。我能够实现大多数KendoUi小部件,但现在我需要使用KendoUi网格控件,它从SQL server获取数据。据我所知,网格小部件使用XML或JSON 所以我有一个db上下文: public DbSet<FranchiseInfoDto> Franchises { get; set; } 序列化的json数据采用以下格式: [{ ParentId: 0,
public DbSet<FranchiseInfoDto> Franchises { get; set; }
序列化的json数据采用以下格式:
[{ ParentId: 0, Title: "Deposit", Type: "link", Link: "http://www.abv.bg" }, { ParentId: 2, Title: "Cash", Type: "link", Link: "http://www.facebook.com"}];
我阅读了有关KendoUI网格的文档,并能够将其绑定到一些本地数据,如:
var menus = [{ ParentId: 0, Title: "Deposit", Type: "link", Link: "http://www.abv.bg" }, { ParentId: 2, Title: "Cash", Type: "link", Link: "http://www.facebook.com"}];
var dataSource = new kendo.data.DataSource({
data: menus,
schema: {
model: {
fields: {
ParentId: { editable: true },
Title: { editable: true },
Type: { editable: true },
Link: { editable: true }
}
}
}
});
$("#grid").kendoGrid({
toolbar: ["create", "save", "cancel"],
columns: [
{
field: "ParentId",
title: "Id",
width: 50
},
{
field: "Title",
title: "Label",
width: 100
},
{
field: "Type",
title: "Type",
width: 100
},
{
field: "Link",
title: "Link"
}
],
dataSource: dataSource,
editable: true,
groupable: true,
scrollable: true,
sortable: true,
pageable: true
});
dataSource: {
type: "odata",
transport: {
read: "Franchise/Index" // this is my controller action //where I serialize the data coming from the local sql server to json
}
但是当我试图将它绑定到返回Json的索引控制器时,我没有成功。我试过这样的方法:
var menus = [{ ParentId: 0, Title: "Deposit", Type: "link", Link: "http://www.abv.bg" }, { ParentId: 2, Title: "Cash", Type: "link", Link: "http://www.facebook.com"}];
var dataSource = new kendo.data.DataSource({
data: menus,
schema: {
model: {
fields: {
ParentId: { editable: true },
Title: { editable: true },
Type: { editable: true },
Link: { editable: true }
}
}
}
});
$("#grid").kendoGrid({
toolbar: ["create", "save", "cancel"],
columns: [
{
field: "ParentId",
title: "Id",
width: 50
},
{
field: "Title",
title: "Label",
width: 100
},
{
field: "Type",
title: "Type",
width: 100
},
{
field: "Link",
title: "Link"
}
],
dataSource: dataSource,
editable: true,
groupable: true,
scrollable: true,
sortable: true,
pageable: true
});
dataSource: {
type: "odata",
transport: {
read: "Franchise/Index" // this is my controller action //where I serialize the data coming from the local sql server to json
}
我对编程相当陌生,我不确定这种方法是否正确。任何基于我的示例代码的示例建议都将不胜感激。谢谢大家! 我设法用从数据库到json的序列化数据填充网格。以下是返回json数据的控制器代码:
public ActionResult SampleData()
{
JsonNetResult jsonNetResult = new JsonNetResult { Formatting = Formatting.Indented };
var f1 = new FranchiseInfoSampleData();
f1.ParentId = 0;
f1.Title = "Deposit";
f1.Type = "functionality";
f1.Link = "http://www.abv.bg";
var f2 = new FranchiseInfoSampleData();
f2.ParentId = 1;
f2.Title = "Cash Out";
f2.Type = "link";
f2.Link = "www.abv.bg";
List<FranchiseInfoSampleData> sampleData = new List<FranchiseInfoSampleData>();
sampleData.Add(f1);
sampleData.Add(f2);
jsonNetResult.Data = sampleData;
return jsonNetResult;
}
我设法用从数据库到json的序列化数据填充网格。以下是返回json数据的控制器代码:
public ActionResult SampleData()
{
JsonNetResult jsonNetResult = new JsonNetResult { Formatting = Formatting.Indented };
var f1 = new FranchiseInfoSampleData();
f1.ParentId = 0;
f1.Title = "Deposit";
f1.Type = "functionality";
f1.Link = "http://www.abv.bg";
var f2 = new FranchiseInfoSampleData();
f2.ParentId = 1;
f2.Title = "Cash Out";
f2.Type = "link";
f2.Link = "www.abv.bg";
List<FranchiseInfoSampleData> sampleData = new List<FranchiseInfoSampleData>();
sampleData.Add(f1);
sampleData.Add(f2);
jsonNetResult.Data = sampleData;
return jsonNetResult;
}
您在Javascript代码中指定启用了serverPaging,但我在ASP.net代码中没有看到任何处理此问题的代码。您在Javascript代码中指定启用了serverPaging,但在ASP.net代码中没有看到任何处理此问题的代码。