This is a migrated thread and some comments may be shown as answers.
Not getting grid data in view model list in save button click
1 Answer 73 Views
This is a migrated thread and some comments may be shown as answers.
Mohammed
Top achievements
Rank 1
Veteran
Mohammed asked on 09 May 2020, 03:15 PM

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!!

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 11 May 2020, 03:12 PM

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.
Tags
Grid
Asked by
Mohammed
Top achievements
Rank 1
Veteran
Answers by
Anton Mironov
Telerik team
Share this question
or