【发布时间】:2015-03-04 20:48:07
【问题描述】:
我正在为 KendoUI 网格制作一个演示页面,我在下面的链接中遵循示例,几乎就像它是“逐字”一样。
http://demos.telerik.com/aspnet-mvc/grid/index
我不确定我做错了什么,但似乎 Grid 没有进行它应该进行的第一个 Ajax 调用。我对 MVC 和 Kendo 都很陌生,但不确定问题是否出在任何特定部分。让我从一些代码 sn-p 开始。我的 Index.CsHTMl 如下所示:
<!DOCTYPE html>
@using (Html.BeginForm())
{
<div id="clientsDb">
@(Html.Kendo().Grid<Prometheus.Core.Domain.Employee>()
.Name("employeeGrid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(140);
columns.Bound(c => c.FirstName).Width(190);
columns.Bound(c => c.LastName);
})
.HtmlAttributes(new {style = "height: 380px;"})
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("ReadEmployee", "EmployeeGrid"))
)
)
</div>
}
<style scoped>
#clientsDb {
width: 952px;
height: 396px;
margin: 20px auto 0;
padding: 51px 4px 0 4px;
background: url('@Url.Content("~/content/web/grid/clientsDb.png")') no-repeat 0 0;
}
</style>
我的控制器如下所示:
public ActionResult Index()
{
return View();
}
[HttpGet]
public ActionResult ReadEmployee([DataSourceRequest]DataSourceRequest request)
{
return Json(GetEmployees().ToDataSourceResult(request),JsonRequestBehavior.AllowGet);
}
public static IEnumerable<Core.Domain.Employee> GetEmployees()
{
return new List<Core.Domain.Employee>
{
new Core.Domain.Employee
{
Id = 1,
FirstName = "Someone",
LastName = "Else"
},
new Core.Domain.Employee
{
Id = 2,
FirstName = "FirstName",
LastName = "LastName"
}
};
}
这几乎复制了演示中的行为:
- 加载 Index.cshtml 时没有从网格发出 Ajax 请求
- 当我自己调用 ReadEmployee ActionMethod 时,它会正确返回 Json。此外,当我单击“空”网格上的任何按钮时,它会加载相同的 JSON。
- 与示例不同,我添加了 BeginForm()。它不适用于有/没有 BeginForm。
有什么想法吗?
【问题讨论】:
标签: ajax asp.net-mvc kendo-ui telerik kendo-grid