How do you set the userdata in the controller action. The way I'm doing it is breaking my grid. I'm trying a simple test with no luck. Here's my code which does not work. Thanks.
如何在控制器动作中设置userdata。我这样做是在破坏我的网格。我正在做一个简单的测试,但运气不好。这是我的不工作的代码。谢谢。
var dataJson = new
{
total =
page = 1,
records = 10000,
userdata = "{test1:thefield}",
rows = (from e in equipment
select new
{
id = e.equip_id,
cell = new string[] {
e.type_desc,
e.make_descr,
e.model_descr,
e.equip_year,
e.work_loc,
e.insp_due_dt,
e.registered_by,
e.managed_by
}
}).ToArray()
};
return Json(dataJson);
1 个解决方案
#1
2
I don't think you have to convert it to an Array. I've used jqGrid and i just let the Json function serialize the object. I'm not certain that would cause a problem, but it's unnecessary at the very least.
我认为你不需要把它转换成数组。我使用了jqGrid,并让Json函数序列化对象。我不确定这是否会引起问题,但这至少是不必要的。
Also, your user data would evaluate to a string (because you are sending it as a string). Try sending it as an anonymous object. ie:
此外,您的用户数据将计算为字符串(因为您将它作为字符串发送)。尝试将其发送为匿名对象。即:
userdata = new { test1 = "thefield" },
You need a value for total and a comma between that and page. (I'm guessing that's a typo. I don't think that would compile as is.)
在total和page之间需要一个逗号。(我猜那是个打字错误。我不认为这能按原样编译。
EDIT: Also, i would recommend adding the option "jsonReader: { repeatitems: false }" to your javascript. This will allow you to send your collection in the "rows" field without converting it to the "{id: ID, cell: [ data_row_as_array ] }" syntax. You can set the property "key = true" in your colModel to indicate which field is the ID. It makes it a lot simpler to pass data to the grid.
编辑:另外,我建议在javascript中添加“jsonReader: {repeatitems: false}”选项。这将允许您在“rows”字段中发送集合,而无需将其转换为“{id: id, cell: [data_row_as_array]}”语法。您可以在colModel中设置属性“key = true”,以指示哪个字段是ID。
#1
2
I don't think you have to convert it to an Array. I've used jqGrid and i just let the Json function serialize the object. I'm not certain that would cause a problem, but it's unnecessary at the very least.
我认为你不需要把它转换成数组。我使用了jqGrid,并让Json函数序列化对象。我不确定这是否会引起问题,但这至少是不必要的。
Also, your user data would evaluate to a string (because you are sending it as a string). Try sending it as an anonymous object. ie:
此外,您的用户数据将计算为字符串(因为您将它作为字符串发送)。尝试将其发送为匿名对象。即:
userdata = new { test1 = "thefield" },
You need a value for total and a comma between that and page. (I'm guessing that's a typo. I don't think that would compile as is.)
在total和page之间需要一个逗号。(我猜那是个打字错误。我不认为这能按原样编译。
EDIT: Also, i would recommend adding the option "jsonReader: { repeatitems: false }" to your javascript. This will allow you to send your collection in the "rows" field without converting it to the "{id: ID, cell: [ data_row_as_array ] }" syntax. You can set the property "key = true" in your colModel to indicate which field is the ID. It makes it a lot simpler to pass data to the grid.
编辑:另外,我建议在javascript中添加“jsonReader: {repeatitems: false}”选项。这将允许您在“rows”字段中发送集合,而无需将其转换为“{id: id, cell: [data_row_as_array]}”语法。您可以在colModel中设置属性“key = true”,以指示哪个字段是ID。