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

Uncaught TypeError: Cannot read property 'index' of undefined Error

0 Answers 388 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Mahmoud
Top achievements
Rank 1
Mahmoud asked on 21 May 2012, 07:15 PM
I'm trying to create a new Category but I get this error
 "Cannot read property 'index' of undefined  Error"

    
<script type="text/javascript">
        $(function () {
            var category = kendo.data.Model.define({
                Id: "Id"
            });
 
            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        url: "/Home/GetCategories",
                        dataType: "json"
                    },//read
                    create : {
                        url: "/Home/CreateCategory",
                        type : "POST",
                        data : {
                            name: $("#categoryName").val()
                        }
                    }
                }, //transport
                schema: {
                    model: category
                }
            });
 
            $("#category").kendoGrid({
                dataSource: dataSource
            });
 
 
            $("#createCategory").bind("click", function () {
               dataSource.add({ Name: $("#categoryName").val() });
                dataSource.sync();
                dataSource.read();
            });
 
        });
    </script>
}
 
<h2>@ViewBag.Message</h2>
 
 
<table id="category">
    <tr>
        <th data-field="Id">ID</th>
        <th data-field="Name">Name</th>
    </tr>
</table>
 
<input type="text" id="categoryName" name="name"/>
<input type="button" value="Create" id="createCategory"/>

No answers yet. Maybe you can help?

Tags
Data Source
Asked by
Mahmoud
Top achievements
Rank 1
Share this question
or