This is in continuation of this thread. I'm using the free-jqGrid 4.9.0 and have inline editing.
{ name: 'ContactName', editable: true, width: 100, sortable: false, frozen: true, formatter: 'select', edittype: 'select',
editoptions: {
dataUrl: '/InvestorList/GetContactList',
postData: function (rowid, value, cmName) {
return { projectId: rowid };
}
}
In my ASP .NET MVC controller, I have the following method:
public JsonResult GetContactList(string projectId)
{
var contacts = new Dictionary<string, string>();//context.GetContactList(projectId);
contacts.Add("123","IAM1");
contacts.Add("1234", "IAM2");
contacts.Add("12345", "IAM3");
return Json(contacts, JsonRequestBehavior.AllowGet);
}
Using IE developer tools, this is the response:
{"123":"IAM1","1234":"IAM2","12345":"IAM3"}
But I get the following error,
Unhandled exception at line 2, column 12461 in http://localhost:51176/Scripts/jquery-2.1.3.min.js 0x800a139e - JavaScript runtime error: Syntax error, unrecognized expression: {"123":"IAM1","1234":"IAM2","12345":"IAM3"}
I'm wondering what kind of format does dataUrl
expect because I use the exact same format for other columns e.g. editoptions: { value: TeaserStatusList }
In this case TeaserStatusList
has the same format as {"123":"IAM1","1234":"IAM2","12345":"IAM3"}
Thanks
Update:
{ name: 'ContactId', editable: true, width: 100, sortable: false, edittype: 'select', editoptions: { dataUrl: '/InvestorList/GetContactList',
postData: function (rowid, value, cmName) {
var accid = $(gridId).jqGrid("getCell", rowid, "AccountId");
return { accountId: accid };
},
buildSelect: function (data) {
var s = "<select>";
data = JSON.parse(data);
$.each(data, function (k, v) {
s += '<option value="' + k + '">' + v + '</option>';
});
return s + "</select>";
}
}