Laurence
Laurence

Reputation: 7823

Kendo UI Grid Update button not firing

I am developing a KendoUI Grid with Inline editable option in javascript and can't make Update button to fire click event and post the data to server side update event. Clicking on Update button won't even update the grid on client.

Hope someone can help me point out what I am doing wrong here.

This is not a duplicate to this as I have tired the jfiddle link in the answer and it is not working too. kendo UI grid update function wont fire

<div id="grid"></div>

 @section Scripts{

<script type="text/javascript">

    $(function () {
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "Home/GetPupilsAsJson",
                    dataType: 'json'
                },                    
                update: {
                    url: "Home/UpdatePupils",
                    dataType: 'json',
                    type: 'POST'
                }
            },
            pageSize: 5,
            autoSync: true                
        });

        $('#grid').kendoGrid({
            dataSource: dataSource,
            editable: "inline",
            pageable: true,
            columns: [{
                field: "Id",
                title: "Id",
                width: 150,
                hidden: true
            }, {
                field: "Firstname",
                title: "Firstname",
                width: 150
            }, {
                field: "Lastname",
                title: "Lastname",
                width: 150
            }, {
                field: "DateOfBirth",
                title: "DateOfBirth",
                width: 150
            }, {
                field: "Class",
                title: "Class",
                width: 150
            }, {
                field: "Year",
                title: "Year",
                width: 150
            },
            {
                command: ["edit"],
                width: 150
            }]
        });       
    });
</script>    
 }

HomeController

 public ActionResult GetPupilsAsJson()
    {            
        return Json(GetPupils(), JsonRequestBehavior.AllowGet);
    }

[AcceptVerbs(HttpVerbs.Post)]
    [HttpPost]
    public void UpdatePupils(Pupil p)
    {
          //never reach here
    }

Upvotes: 0

Views: 10772

Answers (4)

Rabeek Ahamed M
Rabeek Ahamed M

Reputation: 1

Is any of your cell text has HTML tags like < or >, remove them and click on update. The update event will fire.

Upvotes: -1

Abbas Galiyakotwala
Abbas Galiyakotwala

Reputation: 3019

use parameter map to pass model values

<script type="text/javascript">

    $(function () {
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("GetPupilsAsJson", "Home")',,
                    dataType: 'json'
                },                    
                update: {
                    url: '@Url.Action("UpdatePupils", "Home")',
                    dataType: 'json',
                    type: 'POST'
                },
                parameterMap: function (options, operation) {
                   if (operation !== "read" && options.models) {
                      return { models: kendo.stringify(options.models) };
                       }
                }
            },
            pageSize: 5,
            autoSync: true                
        });

Call Controller with parameterMap

public JsonResult UpdatePupils(string models)
        {

            return Json(..);
        }

Upvotes: 0

Laurence
Laurence

Reputation: 7823

I don't know why but fixed it by putting schema information.

schema: {
        model: {
            id: "Id",
            fields: {
                Firstname: { editable: true, validation: { required: true } },
                Lastname: { validation: { required: true } },
                DateOfBirth: { validation: { required: true } },
                Class: { validation: { required: true } },
                Year: { validation: { required: true } }
            }
        }
    }

Upvotes: 5

Jaimin
Jaimin

Reputation: 8020

Use @Url.Action("GetPupilsAsJson", "Home")' so no need to pass base url in your update action like this BASEURL+ "Home/GetPupilsAsJson".

 var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: '@Url.Action("GetPupilsAsJson", "Home")',
                    dataType: 'json'
                },                    
                update: {
                    url:'@Url.Action("UpdatePupils", "Home")',
                    dataType: 'json',
                    type: 'POST'
                }
            },
            pageSize: 5,
            autoSync: true                
        });

Upvotes: 0

Related Questions