【问题标题】:Edit form on JQGrid and ASP.NET MVC 2在 JQGrid 和 ASP.NET MVC 2 上编辑表单
【发布时间】:2011-03-10 18:26:23
【问题描述】:

当我选择一行并按下编辑按钮时,我在 JQgrid 上遇到问题。问题是我想要一个模态编辑表单,它出现在页面顶部,但是当我单击它时,它会关闭。 我查看了 JQgrid 文档并搜索示例,但无法使其正常工作。我正在使用 ASP.NET MVC 2 和 JQgrid 1.4.1,并附加了文件 JqDnr 和 Jqmodal。

<script type="text/javascript">
    var lastsel;

    jQuery(document).ready(function() {
        jQuery("#list").jqGrid({
            url: '/Home/DynamicGridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Id', 'Nombre', 'Sponsor', 'Fecha de Evaluacion', 'Fecha Prevista de Fin', 'Planta', 'Sector', 'LOTO?', 'Trabajo en Altura?', 'Espacio Confinado?', 'Caliente?', 'Amianto?', 'Observaciones'],
            colModel: [
      { name: 'Id', index: 'Id', width: 40, align: 'left', editable: false },
      { name: 'Nombre', index: 'Nombre', width: 200, align: 'left', editable: true },
      { name: 'Sponsor', index: 'Sponsor', width: 80, align: 'left', editable: true, edittype: "select", editoptions: { size: 71} },
      { name: 'Fecha de Evaluacion', index: 'FechaEvaluacion', width: 90, align: 'left', editable: true },
      { name: 'Fecha Prevista de Fin', index: 'FechaPrevistaFin', width: 90, align: 'left', editable: true },
      { name: 'Planta', index: 'Planta', width: 70, align: 'left', editable: true },
      { name: 'Sector', index: 'Sector', width: 70, align: 'left', editable: true },
      { name: 'LOTO?', index: 'PermisoLOTO', width: 50, align: 'left', editable: true, formatter: "checkbox" },
      { name: 'Trabajo en Altura?', index: 'PermisoTrabajoAltura', width: 50, align: 'left', editable: true, formatter: "checkbox" },
      { name: 'Espacio Confinado?', index: 'PermisoEspacioConfinado', width: 50, align: 'left', editable: true, formatter: "checkbox" },
      { name: 'Caliente?', index: 'PermisoCaliente', width: 50, align: 'left', editable: true, formatter: "checkbox" },
      { name: 'Amianto?', index: 'PermisoAmianto', width: 50, align: 'left', editable: true, formatter: "checkbox" },
      { name: 'Observaciones', index: 'Observaciones', width: 200, align: 'left', editable: true}],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'Id',
            sortorder: "desc",
            viewrecords: true,
            imgpath: '/scripts/themes/sand/images',
            caption: 'Tareas'
        }).navGrid("#pager", { edit: true });

    }); 
</script>  

重量

所以,任何帮助都会非常有帮助。谢谢!

【问题讨论】:

    标签: asp.net-mvc-2 jqgrid


    【解决方案1】:

    我无法重现您的问题(请参阅测试here),但我可以肯定地说您必须从colModel 更改name 属性中的值。 name 属性将用作属性名称。它在 Edit 表单中另外构建不同元素的 id。 id 元素如

    id="Fecha Prevista de Fin"
    id="tr_Fecha Prevista de Fin"
    id="Amianto?"
    id="tr_Amianto?"
    

    等等都是不好的。例如,您可以使用 IE 的开发人员工具(在 IE 中按 F12)来检查当前代码的编辑表单中使用的 id。我强烈建议您在名称属性中仅使用 [a-zA-Z0-9] 集中的字符,并以字母开头的名称。名称中不允许有空格(参见herehere)。

    顺便说一句,参数imgpathdeprecated,因为许多 jqGrid 版本,你应该删除它。

    【讨论】:

    • 嗨,谢谢,但我仍然遇到问题,我在下面添加了更多信息。
    • @Hernan:你的意思是在上面而不是下面还是你的评论没有被保存?你还有哪个问题?同样的问题,第一次点击后对话框消失了?我的代码和青春的区别在哪里?
    • 对不起,问题是这样的:“未捕获的异常:jqGrid - 没有这样的方法:restoreRow”当我选择一行时。这就是 Firebug 所显示的。我相信问题出在 Js 文件上,我下载了所有内容并收到此错误。 包含有任何特定顺序吗?
    • @Hernan:当然很重要。查看我的示例并执行相同操作或发布包含所有 JS 的完整 HTML 代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多