I want to return some JSON data from my WebAPI controller and I want the returned data to be like this.
{"rows":[{"id":1,"cell":["1","amila","amila","False"]},{"id":2,"cell":["2","rakhitha","rakhitha","False"]},{"id":3,"cell":["3","Chathura","Chathura","False"]},{"id":4,"cell":["4","Geethaga","Geethaga","False"]}]}
But when I use the below code,
return new System.Web.Mvc.JsonResult()
{
Data = jsonData,
JsonRequestBehavior = System.Web.Mvc.JsonRequestBehavior.AllowGet
};
the data is returned like this.
{"Data":{"rows":[{"id":1,"cell":["1","amila","amila","False"]},{"id":2,"cell":["2","rakhitha","rakhitha","False"]},{"id":3,"cell":["3","Chathura","Chathura","False"]},{"id":4,"cell":["4","Geethaga","Geethaga","False"]}]},"JsonRequestBehavior":0}
There is an additional JSON key as "Data". I dont want that parameter and as my implementation I cant remove this "Data" part after getting it to the client side. Because the data received from the server is directly used to fill a jqGrid. The code is below.
$("#Grid1").jqGrid({
url: 'api/matchingservicewebapi/GetUser',
datatype: 'json',
mtype: 'GET',
colNames: ['', 'Name', 'FullName', 'IsActive'],
colModel: [
{ name: 'Id', index: 'Id', width: 200 },
{ name: 'Name', index: 'Name', width: 300 },
{ name: 'FullName', index: 'FullName', width: 300 },
{ name: 'IsActive', index: 'IsActive', width: 300 }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
sortname: 'Id',
viewrecoreds: true,
sortorder: "desc",
imgpath: 'Themes/images'
}).navGrid(pager, { edit: true, add: true, del: true, refresh: true, search: true });
How do I remove this "Data" part? Because when you have this "Data" key in the returned JSON, jqGrid is not capable of filling that data to the grid.
I am using WebAPI Controller to return this data. But I tried using MVC3 controller, then this "Data" key was not in the returned JSON and data filled to the grid successfully. But I want to use WebAPI Controller. Please help to solve this.
Thank you in advance.