【问题标题】:jqgrid add window parameterjqgrid 添加窗口参数
【发布时间】:2011-06-20 17:22:28
【问题描述】:

我正在使用 MVC 和 jqgrid,我需要从下拉列表中传递一个值来添加或编辑窗口。这是我的代码:

查看:

jQuery("#grid").jqGrid({
            url: '@Url.Content("~/")' + 'Something/GridData/',
            datatype: "json",
            mtype: 'POST',
            colNames: ['Type', 'Product', 'Value1', 'Value2', 'Value3'],
            colModel: [
                { name: 'parType', index: 'parType', width: 80, align: 'center', sortable: false, editable: true, search: false,
                    editrules: { required: true, number: true },
                    editoptions: {
                        dataEvents: [{
                            type: 'keyup',
                            fn: function (e) {
                                if (this.value.match(/\D/)) this.value = this.value.replace(/\D/g, '');
                            }
                        }]
                    }
                },
                { name: 'parProduct', index: 'parProduct', width: 80, align: 'left', editable: true, edittype: "select",
                    editrules: { required: true },
                    editoptions: {
                        multiple: false,
                        size: 1,
                        dataUrl: '@Url.Content("~/")' + 'Something/List/',
                        buildSelect: function (data) {
                            var response = jQuery.parseJSON(data);
                            var s = '<select>';
                            if (response && response.length) {
                                for (var i = 0, l = response.length; i < l; i++) {
                                    var ri = response[i];
                                    s += '<option value="' + ri.Value + '">' + ri.Text + '</option>';
                                }
                            }
                            return s + "</select>";
                        }
                    }
                },
                { name: 'parValue1', index: 'parValue1', width: 80, align: 'right', sortable: false, editable: true, search: false,
                    editrules: { required: true, number: true },
                    editoptions: {
                        dataEvents: [{
                            type: 'keyup',
                            fn: function (e) {
                                if (this.value.match(/\D/)) this.value = this.value.replace(/\D/g, '');
                            }
                        }]
                    }
                },
                { name: 'parValue2', index: 'parValue2', width: 80, align: 'right', sortable: false, editable: true, search: false,
                    editrules: { required: true, number: true },
                    editoptions: {
                        dataEvents: [{
                            type: 'keyup',
                            fn: function (e) {
                                if (this.value.match(/\D/)) this.value = this.value.replace(/\D/g, '');
                            }
                        }]
                    }
                },
                { name: 'parValue3', index: "parValue3", width: 80, align: 'right', editable: true,
                    editrules: { required: true },
                    editoptions: {
                        dataEvents: [{
                            type: 'blur',
                            fn: function (e) {
                                onBlurDecimal(this.id);
                            }
                        }]
                    }
                }],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: jQuery('#pager'),
            sortname: '',
            viewrecords: true,
            sortorder: "asc",
            caption: "Title",
            height: 250,
            width: 700
        });

        jQuery("#grid").jqGrid('navGrid', '#pager',
            { edit: false, add: true, del: true, search: false }, //options
            {url: '@Url.Content("~/")' + 'Something/Add', closeAfterAdd: true, width: 500 },     // add options
            {} // search options
        );


@Html.ValidationSummary(False)
  @Using Html.BeginForm()
   <table>
                    <tr>
                        <td>
                            @Html.Label("ID_CONTRATANTE", "Contratante:")
                            @Html.DropDownListFor(Function(Model) Model.ID_CONTRATANTE, Nothing, New With {.style = "width:300px; visibility:visible", .class = "letraingreso"})
                        </td>
                    </tr>
                </table>
End Using

控制器

Function Add(ByVal parType As Long, ByVal parProduct As Long, ByVal parValue1 As Long, ByVal parValue2 As Long, ByVal parValue3 As String) As ActionResult
        Try
            Dim varE As General1Entities = New General1Entities
            Dim parIDContratante = Request.Form("ID_CONTRATANTE")

            Dim var1 = New OBJECT With { _
                .ID_TYPE = parProduct,
                .ID_CONTRATANTE = parIDContratante,
                .CODE = parType,
                .VALUE1 = parValue1,
                .VALUE2 = parValue2,
                .VALUE3 = parValue3
            }

            varE.AddToOBJECTS(var1)
            varE.SaveChanges()

            Return Json(True)
        Catch ex As Exception
            Return Json(False)
        End Try
    End Function

如您所见,我需要从主视图 (ID_CONTRATANTE) 中获取 DDL 值并将其放入 parIDContratante。显然该值返回 Nothing 因为 jqgrid 的添加窗口是打开的。如何从父视图发送到添加视图窗口这个值?

问候。

【问题讨论】:

    标签: asp.net-mvc-3 jqgrid


    【解决方案1】:

    好的....在寻找解决方案后,我明白了。

    查看(替换旧的 navGrid)

    jQuery("#grid").jqGrid('navGrid', '#pager', {
                edit: false, add: true, del: true, search: false, refresh: false
            }, // general options
            {
            }, // options edit
            {
                url: '@Url.Content("~/")' + 'Something/WorkWith',
                closeOnEscape: true,
                closeAfterAdd: true,
                width: 500,
                modal: true,
                addCaption: 'Nueva Tarifa',
                reloadAfterSubmit: true,
                beforeShowForm: function (frm) { $('#ID_CONTRATANTE').val(); },
                //bottominfo: "Fields marked with (*) are required",
                drag: true,
                onclickSubmit: function (params) {
                    var ajaxData = {};
                    ajaxData = { parIDContratante: $("#ID_CONTRATANTE").val() };
                    return ajaxData;
                }
            }, // options add
            {
                url: "/Something/WorkWith"
            }, // opciones para el dialogo de borrado
            {
            } // options search
            );
    

    控制器(替换旧控制器) 函数 WorkWith(ByVal parFormCollection As FormCollection) As ActionResult 尝试 Dim varE As General1Entities = 新的 General1Entities

                Dim operation = parFormCollection("oper")
                If operation.Equals("add") Then
                 Dim var1 = New OBJECT With { _
                  .ID_TYPE = parFormCollection.Get("parProduct").ToString,
                  **.ID_CONTRATANTE = parFormCollection.Get("parIDContratante").ToString,**
                  .etc.....
                 }
               varE.AddToOBJECTS(var1)
               varE.SaveChanges()
    
                ElseIf operation.Equals("edit") Then
    
                ElseIf operation.Equals("del") Then
    
                End If
    
                Return Json(True)
            Catch ex As Exception
                ' Do some error logging stuff, handle exception, etc.
                Return Json(False)
            End Try
        End Function
    

    我希望这有助于其他一些人。 再见。

    【讨论】:

      猜你喜欢
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多