问题
i use from kendo grid but my grid dont fill with values and when show page grid dont load. i use kendo 2014 and asp.net 2012. my api controller code :
public class ValuesControllerApi : ApiController
{
public List<File> Get()
{
GuaranteeEntities ef = new GuaranteeEntities();
var file = ef.Files.Where(c => c.UpdaterUserInfo == "Guarantee").ToList();
return file;
}
}
and my html Code is :
<div id="employeesGrid">
<script>
$(function () {
$("#employeesGrid").kendoGrid({
dataSource: new kendo.data.DataSource({
transport: {
read: "/api/ValuesControllerApi"
}
})
});
});
$(function () {
$("#employeesGrid").kendoGrid({
columns: [
{ field: "Name" , title:"test" },
{ field: "Family", title: "test test" }
],
dataSource: new kendo.data.DataSource({
transport: {
read: "/api/ValuesControllerApi"
}
}),
sortable: true
});
});
</script>
</div>
回答1:
Try testing your API in the browser alone.
localhost:12345/api/ValuesControllerApi
(change your debugging url as required)
Does that work? Chances are, it doesn't. The reason is because WebApi uses a default pattern for finding the controller end point. You can find more info here.
But to spare you the time, take note of this line:
To find the controller, Web API adds "Controller" to the value of the {controller} variable.
What this means is by default, WebApi assumes all controller classes end in "Controller" when trying to route to an endpoint. In your case, you have named your API ValuesControllerApi
which ends in "Api". Remove the "Api" from the class name and it should work.
So, your class name should look like this: ValuesController : ApiController
and you call it like this: api/Values
回答2:
I think that your controller action won't give Kendo Grid the results in the format it expects. You need to send it a DataSourceRequest. There is a simple example here you may check.
Also this documentation article should shed some light on the issue too.
Hope it helps!
来源:https://stackoverflow.com/questions/23799214/fill-kendogrid-with-api-controller-in-asp-net