far jack
far jack

Reputation: 25

Upon button click how to make request using javascript and call read method by using ajax MVC Kendo UI grid

Since long time i am working on telerik extentions for MVC, Now our company have Kendo UI lic. and they want to to convert my pages, Now i am facing lot of issues.I found of examples but some code is still missing.

I found code

 public ActionResult BulkEdit([DataSourceRequest]DataSourceRequest request)
{        
    var NewAssets = db.TurnaroundDumps;
    DataSourceResult result = NewAssets.ToDataSourceResult(request)
    return Json(result, JsonRequestBehavior.AllowGet);
}

and

@(Html.Kendo().Grid<PcInventory_v1_1.Models.TurnaroundDump>()
.Name("Grid")
.Columns(columns =>
{
    columns.Bound(p => p.AssetTag);
    columns.Bound(p => p.SerialNumber);
    columns.Bound(p => p.DeptId);
    columns.Bound(p => p.Location);
})
    .DataSource(dataSource => dataSource
        .Ajax() // Specify that the data source is of ajax type
        .Read(read => read.Action("BulkEdit", "Assets")) 
        // Specify the action method and controller name
    ).Pageable()
)

But i do not find javascript where they are creating request.

Actually i want to get my result back on button click, When user will click search button then i want to pass request object to the method, but i do not know how i will do that with Kendo UI.

Thanks

Upvotes: 0

Views: 1133

Answers (1)

Petur Subev
Petur Subev

Reputation: 20203

Basically to perform request to the server you should play with the dataSource object of the Grid and more specifically the read one.

$('#gridName').data().kendoGrid.dataSource.read({someExtraParamIfYouWant:"SomeValue"});

The code above will reach the action method specified by your dataSource declaration and pass any values (if you pass any).

Also the page,filter, sorting, grouping etc. will be passed to the action method and the DataSourceRequest object will contain them.

Upvotes: 1

Related Questions