Not getting grid data in view model list in save button click

2 posts, 0 answers
  1. Mohammed
    Mohammed avatar
    26 posts
    Member since:
    May 2020

    Posted 09 May 2020 Link to this post

    Hi ,

    I have a Grid with Data binded and Save button outside the grid , i need to POST the grid data   from view to controller action method  in Save button click, i am getting count 0 in the list in the action method when POST. Is there a way to read grid data and get as list, i want in server side.

    Note the Grid is inside tabstrip control

    Help will be appreciated!!

  2. Anton Mironov
    Admin
    Anton Mironov avatar
    204 posts

    Posted 11 May 2020 Link to this post

    Hello, Mohammed,

    Sending the Kendo UI Grid data to a method in the controller could happen with the help of an ajax request.

    Within the click event handler of a button, access the data of the grid and perform the request:
    @(Html.Kendo().Button()
        .Name("postButton")
        .HtmlAttributes( new {type = "button"} )
        .Content("Save")
        .Events(e => e.Click("onClick"))
    )
    The handler below sends the data to GridController's GetGridInfo method in the required format:
    function onClick() {
            var grid = $("#kendogrid").data("kendoGrid");
            var dataSource = grid.dataSource;
    
            var rows = JSON.stringify({ 'rows': dataSource.data().toJSON() });
    
            $.ajax({
                url: "/Grid/GetGridInfo",
                data: rows,
                dataType: "json",
                type: "POST",
                contentType: 'application/json;'
            });
        }

    Here is the method in GridController that will receive the grid's view data:

    [HttpPost]
            public ActionResult GetGridInfo(List<GridRowViewModel> rows)
            {
                //Use rows for the application needs
            }

    I hope you find this helpful.

     

    Regards,
    Anton Mironov
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top