【问题标题】:Issue in binding kendo grid with web api hosted on Azure将剑道网格与 Azure 上托管的 Web api 绑定的问题
【发布时间】:2014-07-24 21:01:16
【问题描述】:

我正在努力将剑道网格与 Web API 绑定。 Web API 托管在 Azure 辅助角色(尚未发布)中。并且 Web API 被修饰以便与跨域一起工作,即为 Web API 启用 CORS。

让我们看看我写的代码。

Web API 中的操作方法如下所示。

public JToken Get()
{
    JToken json = JObject.Parse(
      "{ \"firstName\": \"John\",
         \"lastName\": \"Smith\",
         \"isAlive\": true,
         \"age\": 25, 
         \"height_cm\": 167.6, 
         \"address\":
         {      
             \"streetAddress\": \"21 2nd Street\",
             \"city\": \"New York\",
             \"state\": \"NY\",
             \"postalCode\": \"10021-3100\"    
         }, 
         \"phoneNumbers\": 
         [{ 
             \"type\": \"home\", 
             \"number\": \"212 555-1234\"
         },        
         { 
             \"type\": \"office\",  
             \"number\": \"646 555-4567\" 
         }]
       }"
    );
    return json;
}

当我执行这个 web api 时,我们将获得 IP 地址为“127.0.0.1”的模拟器,我使用了控制器 "TestController"

当我在浏览器中执行上面的api时,我得到了完美的JSON数据,但是当我用它来绑定网格时,一切都是徒劳的。

用于绑定数据的代码是

$("#dw_report_container1").kendoGrid({
    dataSource: {
        type: "json",
        transport: {
            read: {
                url: "http://127.0.0.1/test",
                dataType: "json"
            }
        },
    },
    height: 500,
    scrollable: true,
    selectable: true
});

我也不例外。

【问题讨论】:

  • 您还没有在 Grid 上声明任何列,您尝试过吗?
  • 如果我想要所有列,则不需要特定列。那没关系。即使我使用了这些列,同样的问题。

标签: azure asp.net-web-api kendo-ui kendo-grid


【解决方案1】:

最后,经过长时间的努力,我得到了解决方案:(。我在使用剑道网格时发现了一件奇怪的事情。每当我们在项目中使用模型并将模型返回到剑道网格的数据源时,它在内部为它创建一个模型。当我使用上面的示例 json 时,它(kendogrid)不会为要绑定的网格创建模型。因此出现了问题。最终,我得出的结论是最好有一个模式/数据源中的模型(剑道网格)。过去我没有:(谢谢。

【讨论】:

    猜你喜欢
    • 2018-09-21
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多