Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am struggling in order to bind the kendo grid with Web API. Web API is hosted in the Azure worker role (not yet published). And the Web API is decorated in order to work with the cross domains i.e Enabled CORS for the Web API.

Let us look the code I have written.

Action method in the Web API look like the following.

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


When I execute this web api we will get the emulator with the IP address as "127.0.0.1" and I used the controller "TestController".

When I execute the above api in the browser, I am getting the JSON data perfectly, but when I use the same to bind the grid, all is vain.

The code used to bind the data is

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


I am getting an exception of "Undefined is not an object".

Please provide the solution.
Posted
Updated 23-Jul-14 21:25pm
v3

1 solution

Finally, after a long struggle i got the solution :(.
I find a strange thing when working with the kendo grid. Whenever we work with the models inside our project and returned the model to the datasource of the kendogrid, it internally creates a model for it. As i worked with sample json as above, it (kendogrid) doesn't create the model for the grid to bind. Hence the problem occurs.
Eventually, what i concluded that it is better to have a schema/model in the datasource (kendo grid). Past i didn't :(.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900