This is a migrated thread and some comments may be shown as answers.

Bind kendo-ui grid to MVC ApiController

1 Answer 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Syl'
Top achievements
Rank 1
Syl' asked on 13 Jun 2014, 03:04 PM
Hello,

I'm using Kendo-ui JQuery version, and I'm trying to fill a kendo-ui grid from an ApiController.
My grid remains empty... What am I missing ?

Here is the result of my ApiController : ~/api/Countries :

[{"Id":4,"Name":"Germany"},
 {"Id":5,"Name":"China"},
 {"Id":6,"Name":"Myanmar"}]


Here is my ApiController code :

public class CountriesController : ApiController
{
    private DBContext db = new DBContext();
 
    // GET api/Countries
    [Queryable]
    public IQueryable<Country> GetCountries()
    {
        return db.Countries;
    }
}


Here is my cshtml code :

<script type='text/javascript'>
 
    $(document).ready(function () {
        $("#grid").kendoGrid({
            columns: [
                { field: "Id", title: "id" },
                { field: "Name", title: "name" }
            ],
            dataSource: new kendo.data.DataSource({
                transport: {
                    read: "api/Countries"
                },
                schema: {
                    model: {
                        id: "Id",
                        fields: {
                            Id: { type: "number" },
                            Name: { type: "string" }
                        }
                    }
                },
                pageSize: 3
            }),
            pageable: true
        });
    });
 
</script>


Thanks for your help.

1 Answer, 1 is accepted

Sort by
0
Syl'
Top achievements
Rank 1
answered on 13 Jun 2014, 06:08 PM
It works now. The problem was the url : "api/Countries" instead of "/api/Countries".
Tags
Grid
Asked by
Syl'
Top achievements
Rank 1
Answers by
Syl'
Top achievements
Rank 1
Share this question
or