0

I am using Multiselect feature to select rows and pass the data to the controller using getRowData to pass the whole row instead of passing individual cell values. I am having onSelectRow event fired when the user selects a checkbox for a single row. I am able to retrieve the row data using getRowData and pass it to the controller which accepts a string but the data is null. Below is my onSelectRow event.

onSelectRow: function (row_id) {

var rowData = $("#employee").getRowData(row_id);
$.ajax({
     type: 'POST',
     url: '/Home/Create/',
     data: { gridData: rowData },
     dataType: "json"
});

This is my controller action that's accepting a string parameter.

public ActionResult Create(string gridData) {}

I have read other posts and tried to use Json.stringify before sending to the controller but I am having difficulty to convert it to the format that I needed, so getting the row data would be more flexible for me to manipulate it.

What should be the paramter that my controller action should accept to retrieve the gridData appropriately?

Any suggestion is greatly appreciated!

inspiringmyself
  • 590
  • 1
  • 11
  • 29

1 Answers1

0

okay i got your problem, first instead of passing row_id do like this

var sel_id = jQuery("#grid").jqGrid('getGridParam', 'selrow');

this will give you the id of selected row and then you can get the data like this

var val =  jQuery("#grid").jqGrid('getRowData', sel_id);

and then when you are sending the data you need to stringfy it...let me show you one example where i'm selecting all rows and sending data to controller...look at my answer here

OnClickButton function parameter for MultiSelect jqgrid MVC3

Community
  • 1
  • 1
Piyush Sardana
  • 1,748
  • 4
  • 19
  • 33
  • @LeftyX: Hello, I have tried to use this method to pass one parameter to dataInit-method, but at the moment of firing of dataInit the selected row seems to be unknown:'dataInit'=> "function (elem) {var sel_id =jQuery('#grid').jqGrid('getGridParam','selrow');alert(sel_id);}" The alert is empty.It's not logical for me as I do select the row and then I load the form editing for the given row, why I do not have the selrow? I seek the opportunity to use a parameter for data initialization in selectlist:'dataUrl'=>'/script/?id='+jQuery("#grid").jqGrid('getRowData', sel_id); How can I achieve this? – Anatoliy Aug 20 '12 at 07:01