Click here to Skip to main content
14,668,804 members
Rate this:
Please Sign up or sign in to vote.
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.

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

$("#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

Rate this:
Please Sign up or sign in to vote.

Solution 2

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 :(.
   
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100