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

Grid's create, update and destroy operations are calling a single URL assigned to Create.

1 Answer 1162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 09 May 2013, 04:15 PM
I am having a problem with Kendo UI Grid. I am able to read data from the server. But when I update, create or delete a row in the grid, it is redirecting only to “Create”. Below is my code in jQuery/JS and ASP.NET :
 
.CSHTML CODE

$("#employeesGrid").kendoGrid({
        toolbar: ["create"],
        // dataSource: myDataSource2,
        dataSource: new kendo.data.DataSource({
            transport: {
                read: { url: "@Url.Action("GetEmployeesList","Employee")" },
                update: {url: "@Url.Action("UpdateEmployee", "Employee")" },
                destroy: { url: "@Url.Action("DeleteEmployee", "Employee")" },
                create: {url: "@Url.Action("CreateEmployee", "Employee")" }            
            },
            schema: {
                model: {
                    fields: {
                        FirstName: { editable: false},
                        DOB: { type: "date"},
                        Created: {type: "date" },
                        Updated: {type: "date" },
                    }
                }
            },
            pageSize : 3,
            serverPaging : true
        }),
        columns: [
            { field: "FirstName", title: "First Name" },
            { field: "LastName", title: "Last Name"},
            { field: "DOB", title: "Date of Birth", format: "{0:dd/MM/yyyy}" },
            { 
                field: "Role", title: "Role", values: [
                            { text: "Software Engineer", value: "Software Engineer"},
                            { text: "Team Lead", value: "Team Lead"},
                            { text: "Project Manager", value: "Project Manager"},
                            { text: "Technical Architect", value: "Technical Architect"},
                            { text: "Other", value: "Other"}
                ] 
            },
            { field: "Enabled", title: "Enabled" },
            { command: ["edit", "destroy"], title: " ", width: "172px" }
        ],
        filterable: true,
        sortable: true,
        pageable: true,
        editable: "popup"
    });
});

 
ASP.NET Controller Code :
[HttpGet]
public JsonResult GetEmployeesList(int take, int skip, int page, int pageSize)
{
var em = (from e in es.Find()
                     select e.ToModel()).Skip(skip).Take(take).ToList();
return Json(em, JsonRequestBehavior.AllowGet);
}
 
public JsonResult UpdateEmployee(EmployeeModel empModel)
{

}
 
public JsonResult CreateEmployee(EmployeeModel empModel)
{

}
 
public JsonResult DeleteEmployee(EmployeeModel empModel)
{

}
 
I placed breakpoints, the kendo ui grid code only goes to CreateEmployee method for create, update and delete operations. 

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 10 May 2013, 07:43 AM
Hi Kiran,

I already replied to your question in the support thread that you submitted on the same subject. For convenience I will paste my reply on the forum as well.

This problem occurs because your model does not have an ID. The model ID is essential for editing functionality and should not be ommited - each dataSource records should have unique ID, records with empty ID field are considered as new and are submitted through the "create" transport.

schema: {
    model: {
        //id? model must have an unique ID field
        fields: {
            FirstName: { editable: false},
            DOB: { type: "date"},
            Created: {type: "date" },
            Updated: {type: "date" },
        }
    }
},

For more information on the subject, please check the following resources:

I hope this information will help. Wish you a great day.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Kiran
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or