如何绑定剑道网格
本文关键字:网格 绑定 何绑定 | 更新日期: 2023-09-27 18:29:33
我已经创建了asp.net MVC 4应用程序,我在其中使用实体框架,类"Data"是模型。
AdventureWorksTrainingEntities _dbContext = new AdventureWorksTrainingEntities();
Data _data = new Data(); //Model
我想将表格的数据显示到剑道网格中。在控制器中,我使用以下代码:
public ActionResult Index()
{
List<Movie> dataForGrid= _dbContext.Movies.ToList();
return View(dataForGrid);
}
类似
在类别Controller.cs 中
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.chtml 中
@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")