我已经创建了asp.net MVC 4应用程序,我正在使用实体框架,类“Data”就是模型。
AdventureWorksTrainingEntities _dbContext = new AdventureWorksTrainingEntities();
Data _data = new Data(); //Model
我想将表的数据显示到kendo网格。在控制器中,我使用以下代码:
public ActionResult Index()
{
List<Movie> dataForGrid= _dbContext.Movies.ToList();
return View(dataForGrid);
}
答案 0 :(得分:1)
类似
private Entities db = new Entities();
public ActionResult GetItemCategories(GridParams g, string title)
{
title = (title ?? "").ToLower();
Expression<Func<tbl_Category, bool>> ff = i => i.Name.ToLower().Contains(title);
var rs = db.tbl_Category.AsExpandable().Where(ff).OrderBy(o => o.Name);
return Json(new GridModelBuilder<Models.tbl_Category>(rs, g) { }.Build());
}
在Index.cshtml中
@Html.Awe().Grid("grid_Category").Columns(
new Column { Name = "ID", Width = 55, Groupable = false, },
new Column { Name = "Name" },
new Column { Name = "NameDisplay" },
new Column { Name = "SortID" },
new Column { ClientFormat = editFormat, Width = 48 },
new Column { ClientFormat = deleteFormat, Width = 48 }
).Url(Url.Action("GetItemCategories", "Category")).Persistence(Persistence.Session
).Sortable(true
).Groupable(false).SingleColumnSort(true
).ShowGroupedColumn(false
).Height(200
).MinHeight(100
).PageSize(10).Parent("txtTitle", "title")