用ASP.NET中的api控制器填充kendogrid [英] fill kendogrid with api controller in asp.net

查看:67
本文介绍了用ASP.NET中的api控制器填充kendogrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Kendo网格使用,但是我的网格未填充值,并且显示页面网格未加载. 我使用kendo 2014和asp.net 2012. 我的api控制器代码:

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;
    }
}

我的html代码是:

 <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>

推荐答案

尝试仅在浏览器中测试您的API.

Try testing your API in the browser alone.

localhost:12345/api/ValuesControllerApi (根据需要更改调试网址)

这行得通吗?可能是,不是.原因是因为WebApi使用默认模式来查找控制器端点.您可以找到更多信息在这里.

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:

要查找控制器,Web API将"Controller"添加到{controller}变量的值中.

To find the controller, Web API adds "Controller" to the value of the {controller} variable.

这意味着默认情况下,WebApi假定所有控制器类在尝试路由到端点时都以" Controller "结尾.在您的情况下,您已经命名了以< Api 结尾的API ValuesControllerApi.从类名称中删除" Api ",它应该可以工作.

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.

因此,您的班级名称应如下所示:ValuesController : ApiController

So, your class name should look like this: ValuesController : ApiController

,您这样称呼它:api/Values

这篇关于用ASP.NET中的api控制器填充kendogrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆