【发布时间】:2012-09-11 22:42:05
【问题描述】:
我已经看到了大量关于在视图中设置 colmodel 的示例,但我无法看到控制器代码! 我正在尝试这样做,但设置一直出错。 我正在尝试达到此列的形成:
colModel:
[
{ name: 'ID', index: 'ID', hidden: true },
{ name: 'Votes', index: 'Votes', width: 100, align: 'left' },
{ name: 'Question', index: 'Question', width: 300, align: 'left' },
{ name: 'my_clickable_checkbox', index: 'my_clickable_checkbox',
sortable: true,
formatter: chkFmatter, formatoptions: { disabled: false }, editable: true,
edittype: "checkbox"
}
],
这是我在控制器中的试用:
return Json(
new { colNames = new[] { "ID2", "Votes2", "Question2", "checkbox" },
colModel = new[] {
new { name = "ID", index = "ID", width = 0, formatter="",
edittype="", hidden = true },
new { name = "Votes", index = "Votes", width = 100, formatter="",
edittype="", hidden = false },
new { name = "Question", index = "Question", width = 300, formatter="",
edittype="", hidden = false },
new { name = "checkbox", index = "my_clickable_checkbox", width = 100,
formatter="chkFmatter", edittype="checkbox", hidden = false }
}
}, JsonRequestBehavior.AllowGet);
在控制器中创建这个数组迫使我在所有行中拥有相同数量的属性。例如,我只需要隐藏ID,但它强制我为所有其他列提供hidden 属性。
第二个问题,第四列需要调用js函数chkFmatter。
如何在控制器中达到 colModel 格式??
非常感谢。
【问题讨论】:
标签: asp.net-mvc-3 jqgrid