This question is locked. New answers and comments are not allowed.
Assume you define the .Ajax() method on your grid without any routeValues (but your ActionMethod has a parameter defined). If you call the client-side grid rebind() method and pass in routeValue arguments, they never get sent to the controller's actionmethod. The reason seems to be that this javascript below is doing a regex replace so the new route value you specified in the client-side rebind() method doesn't get added
for (var key in args) {
var regExp = new RegExp($t.formatString('({0})=([^&]*)', key), 'g');
this.ajaxUrl = this.ajaxUrl.replace(regExp, '$1=' + args[key]);
}
The problem is that now I am forced to specify my routeValues (searchCriteria) on the grid definition. But the first time I load the grid, I don't have a value for searchCriteria. The workaround (hack) that I found is to specify a blank space in the searchCriteria routeValue, since I can't pass in null or an empty string. Then I do a C# 4 string.IsNullOrWhiteSpace check in the action method to make sure its not the blank space being sent it.
Details:
--------------------------------------------------------------------------------
My controller action method
My grid (with the hack of specify a blank space for the search criteria)
jQuery call to search the grid
for (var key in args) {
var regExp = new RegExp($t.formatString('({0})=([^&]*)', key), 'g');
this.ajaxUrl = this.ajaxUrl.replace(regExp, '$1=' + args[key]);
}
The problem is that now I am forced to specify my routeValues (searchCriteria) on the grid definition. But the first time I load the grid, I don't have a value for searchCriteria. The workaround (hack) that I found is to specify a blank space in the searchCriteria routeValue, since I can't pass in null or an empty string. Then I do a C# 4 string.IsNullOrWhiteSpace check in the action method to make sure its not the blank space being sent it.
Details:
--------------------------------------------------------------------------------
My controller action method
| [GridAction] |
| public ActionResult MyActionMethod(string searchCriteria) |
| { |
| //pass a gridmodel to the view |
| } |
My grid (with the hack of specify a blank space for the search criteria)
| <%= Html.Telerik().Grid(Model) |
| .Ajax(ajax => ajax.Action("MyActionMethod", "MyController", new { searchCriteria = " " })) |
| %> |
jQuery call to search the grid
| var grid = $('#Grid').data('tGrid'); |
| grid.rebind({searchCriteria: $(this).val()}); |