I am using Multiselect feature to select multiple rows and pass to the controller. The javascript is below:
onClickButton: function (ids) {
var grid = $("#employee");
var rowid = grid.jqGrid('getGridParam', 'selarrrow');
var count = rowid.length;
var rowData;
var colData = [];
for (var i = 0; i < count; i++) {
rowData = $("#employee").getRowData(rowid[i]);
colData[i] = rowData.ID;
}
$.ajax({
type: 'POST',
url: '/Home/Create/' + colData,
//data: { id: colData },
dataType: "json"
});
}
My controller action is below:
public ActionResult Create(string id){
JavaScriptSerializer ser = new JavaScriptSerializer();
var myList = ser.Deserialize<List<string>>(id);}
I am creating colData as an array and currently adding four IDs to it (“102,103,104,105”). When I debug and look at the colData, it contains “102,103,104,105”. Then, I pass it to the controller action as a string and then deserialize it. When I deserialize it, it complains as “Invalid JSON primitive: 103,104,105.”
I have seen other posts but couldn’t find anything related to my issue. When I pass colData using “data: { id: colData }”, id is returned as null.
Please help me figure out this issue, it’s been a while I am stuck with this one. Any suggestions greatly appreciated.
when you are sending your data through ajax call you need to stringyfy your data like this
I hope this helps.