2011-06-20 19 views
0

私はMVCとjqgridを使用していますので、ウィンドウを追加または編集するにはdropdownlistから値を渡す必要があります。これは私のコードです: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のウィンドウが開いているためです。この値をビューウィンドウに追加するには、どのように親ビューから送信できますか?

よろしくお願いいたします。

答えて

1

Ok ....解決策を探した後、私はそれを手に入れます。 General1Entities =新General1Entities

として 点心varEを試してみてのActionResult として

ビュー(旧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(FormCollectionとしてByVal parFormCollection)

  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 

else。 さようなら。

関連する問題