MVC Kendo 网格多选列
MVC Kendo Grid multiselect column
我有一个 kendo mvc 网格。
我希望其中一列是值列表。
例如我的数据对象:
public TestObject()
{
public int TestID {get; set;}
public string MyTest {get; set;}
public string MyCategory {get; set;}
public string Description {get; set;}
}
Kendo 网格:
@(Html.Kendo().Grid<MyProject.BusinessObjects.TestObject>()
.Name("myGrid")
.Columns(col =>
{
col.Bound(x => x.TestID);
col.Bound(x => x.MyTest);
col.Bound(x => x.MyCategory);
col.Bound(x => x.Description);
col.Command(x => { x.Edit(); x.Destroy(); });
})
.Selectable()
.Scrollable()
.ToolBar(x => x.Create())
.Sortable()
.Editable(e => e.Mode(GridEditMode.PopUp))
.Pageable(p => p
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(d => d
.Ajax()
.Read(r => r.Action("GetData", "MyController"))
.PageSize(20)
.Model(m =>
{
m.Id(x => x.TestID);
})
.Update("UpdateData", "MyController")
.Create("CreateData", "MyController")
.Destroy("DeleteData", "MyController")
)
)
现在,当用户添加或编辑记录时,我希望 MyCategory 显示有效值列表。 (基本上 MyCategory 是一个 FK,但在数据库中没有强制执行)
如何使用 Kendo 网格完成此操作?我试图按照 Kendo 在线示例进行操作,但是当他们创建 ViewState 对象时我缺少连接以及网格如何与该特定对象交互。
(Kendo 网格编辑自定义编辑器示例)
在 DB 中不必是 fk。
columns.ForeignKey(p => p.MyCategory, (System.Collections.IEnumerable)ViewData["MyCategory"], "Id", "MyCategoryText");
并且在控制器索引页面中,您必须填充视图数据。您可以从数据库中获取数据,也可以对值进行硬编码。
public ActionResult Index()
{
ViewData["MyCategory"] = GetMyCategoryList();
return View();
}
public List<SelectListItem> GetMyCategoryList()
{
List<SelectListItem> lstMyCategory = new List<SelectListItem>();
var data = new[]{
new SelectListItem{ Id=1,MyCategoryText="Federal"},
new SelectListItem{ Id=2,MyCategoryText="General"},
new SelectListItem{ Id=3,MyCategoryText="Cash"},
};
lstMyCategory = data.ToList();
return lstMyCategory;
}
我有一个 kendo mvc 网格。
我希望其中一列是值列表。
例如我的数据对象:
public TestObject()
{
public int TestID {get; set;}
public string MyTest {get; set;}
public string MyCategory {get; set;}
public string Description {get; set;}
}
Kendo 网格:
@(Html.Kendo().Grid<MyProject.BusinessObjects.TestObject>()
.Name("myGrid")
.Columns(col =>
{
col.Bound(x => x.TestID);
col.Bound(x => x.MyTest);
col.Bound(x => x.MyCategory);
col.Bound(x => x.Description);
col.Command(x => { x.Edit(); x.Destroy(); });
})
.Selectable()
.Scrollable()
.ToolBar(x => x.Create())
.Sortable()
.Editable(e => e.Mode(GridEditMode.PopUp))
.Pageable(p => p
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(d => d
.Ajax()
.Read(r => r.Action("GetData", "MyController"))
.PageSize(20)
.Model(m =>
{
m.Id(x => x.TestID);
})
.Update("UpdateData", "MyController")
.Create("CreateData", "MyController")
.Destroy("DeleteData", "MyController")
)
)
现在,当用户添加或编辑记录时,我希望 MyCategory 显示有效值列表。 (基本上 MyCategory 是一个 FK,但在数据库中没有强制执行)
如何使用 Kendo 网格完成此操作?我试图按照 Kendo 在线示例进行操作,但是当他们创建 ViewState 对象时我缺少连接以及网格如何与该特定对象交互。
(Kendo 网格编辑自定义编辑器示例)
在 DB 中不必是 fk。
columns.ForeignKey(p => p.MyCategory, (System.Collections.IEnumerable)ViewData["MyCategory"], "Id", "MyCategoryText");
并且在控制器索引页面中,您必须填充视图数据。您可以从数据库中获取数据,也可以对值进行硬编码。
public ActionResult Index()
{
ViewData["MyCategory"] = GetMyCategoryList();
return View();
}
public List<SelectListItem> GetMyCategoryList()
{
List<SelectListItem> lstMyCategory = new List<SelectListItem>();
var data = new[]{
new SelectListItem{ Id=1,MyCategoryText="Federal"},
new SelectListItem{ Id=2,MyCategoryText="General"},
new SelectListItem{ Id=3,MyCategoryText="Cash"},
};
lstMyCategory = data.ToList();
return lstMyCategory;
}