简体   繁体   中英

Force Telerik Grid to use GET in AJAX data binding

I have following code in an old application that uses Telerik Grid. The ajax request to the server is always using POST. I need to change it to GET, but I can't find any documentation since it is an older version (not Kendo Grid, just Telerik Grid). Any ideas how to fix that?

Html.Telerik().Grid<GridDataRow>()
          .Name("gridRecipientList")
          .Columns(columns => ...)                                       
          .DataBinding(dataBinding =>
             dataBinding.Ajax().Select("MyAction", "MyController"))
          .Pageable(settings => ...)
          .PrefixUrlParameters(false)
          .EnableCustomBinding(true)
          .Sortable(sorting => sorting
             .SortMode(Telerik.Web.Mvc.UI.GridSortMode.SingleColumn)
             .OrderBy(order=>order.Add(f=>f.P1)))
          .Scrollable(settings => settings.Height(300))
          .Resizable(resizing => resizing.Columns(true))

Posting the answer in hope that it helps someone else. I could define a client-side handler and explicitly set the verb used for read operation:

var onGridLoaded = function (e) {
  var telerikGridData = $("div#gridRecords").data('tGrid');
  if (telerikGridData != null) {
    telerikGridData.ajax.options.transport.read.type = "GET";
  }
};

And to bind the this function to the grid I added this to the server-side code above:

.ClientEvents(events => {
  events.OnGridLoaded("onGridLoaded");
 })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM