【发布时间】:2014-06-13 13:56:45
【问题描述】:
我正在使用 Kendo-ui JQuery 版本,并且正在尝试从 ApiController 填充 kendo-ui 网格。我的网格仍然是空的...我错过了什么?
这是我的 ApiController 的结果:~/api/Countries :
[{"Id":4,"Name":"Germany"},
{"Id":5,"Name":"China"},
{"Id":6,"Name":"Myanmar"}]
这是我的 ApiController 代码:
public class CountriesController : ApiController
{
private DBContext db = new DBContext();
// GET api/Countries
[Queryable]
public IQueryable<Country> GetCountries()
{
return db.Countries;
}
}
这是我的cshtml代码:
<script type='text/javascript'>
$(document).ready(function () {
$("#grid").kendoGrid({
columns: [
{ field: "Id", title: "id" },
{ field: "Name", title: "name" }
],
dataSource: new kendo.data.DataSource({
transport: {
read: "api/Countries"
},
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number" },
Name: { type: "string" }
}
}
},
pageSize: 3
}),
pageable: true
});
});
</script>
感谢您的帮助。
【问题讨论】:
-
看网络流量,是否有对api/Countries的请求,如果有,响应码是什么?
-
谢谢Robin,我平时会检查网络流量,但这次没有做。不知道为什么!!无论如何,响应是空的,因为在我的情况下 url 应该是“/api/Countries”而不是“api/Countries”。有效!
标签: asp.net-mvc-4 asp.net-web-api kendo-ui kendo-grid asp.net-apicontroller