2012-04-04 23 views
0

我有在单独的对话框中打开一个Razor视图2种形式。的形式使用jQuery后提交..MVC在单一视图多种形式不工作

第一种形式完美的作品,但第二种形式的心不是在所有公认的,当我尝试serializr数据则返回一个空字符串。下面

代码:

@using (Html.BeginForm("SaveElectricReading", "Store", FormMethod.Post, new { id = "frmSaveElectricReading" })) 
{ 
    <div id="electricDialog" style="display: none;" title="Electric Readings"> 
     <p> 
      Please ensure the electric readings have been entered! 
     </p> 
     <table width="100%"> 
      <tr> 
       <th> 
        Serial: 
       </th> 
      </tr> 
      <tr> 
       <td> 
        <input type="text" name="Serial" /> 
       </td> 
      </tr> 
      <tr> 
       <th> 
        Reading: 
       </th> 
      </tr> 
      <tr> 
       <td> 
        <input type="text" name="Reading" /> 
       </td> 
      </tr> 
      <tr> 
       <th> 
        Comment: 
       </th> 
      </tr> 
      <tr> 
       <td> 
        <div class="textwrapper"> 
         <textarea rows="5" cols="10" name="Comment"></textarea> 
        </div> 
       </td> 
      </tr> 
     </table> 
    </div> 
} 

@using (Html.BeginForm("SaveWaterReading", "Store", FormMethod.Post, new { id = "myform" })) 
{ 
    <div id="waterDialog" style="display: none;" title="Water Readings"> 
     <p> 
      Please ensure the water readings have been entered! 
     </p> 
     <table width="100%"> 
      <tr> 
       <th> 
        Serial: 
       </th> 
      </tr> 
      <tr> 
       <td> 
        <input type="text" name="WaterSerial" /> 
       </td> 
      </tr> 
      <tr> 
       <th> 
        Reading: 
       </th> 
      </tr> 
      <tr> 
       <td> 
        <input type="text" name="WaterReadingsdfsdf" /> 
       </td> 
      </tr> 
      <tr> 
       <th> 
        Comment: 
       </th> 
      </tr> 
      <tr> 
       <td> 
        <div class="textwrapper"> 
         <textarea rows="5" cols="10" name="WaterComment"></textarea> 
        </div> 
       </td> 
      </tr> 
     </table> 
    </div> 
} 

function showWaterDialog() { 
    var $dialog = $('#waterDialog').dialog({ 
     autoOpen: false, 
     modal: true, 
     width: 400, 
     height: 400, 
     buttons: { 
      Submit: function() { 
       //    $('#frmCreateStore').submit(); 
       var data = $('#frmSaveWaterReading'); 

       $.post("/Store/SaveWaterReading", 
        $("#frmSaveWaterReading").serialize(), 
        function() { 
         $("#waterDialog").dialog("close"); 
        }); 
       //$(this).dialog("close"); 
      }, 
      Cancel: function() { 
       $(this).dialog("close"); 
      } 
     } 
    }); 

    $dialog.dialog('open'); 
} 
+0

id为第二的应读** ** frmSaveWaterReading而不是** ** myForm的我使用调试它。 – user1314014 2012-04-05 09:31:24

+0

我还可以看到,第二种形式似乎不具有任何相关的元素呢? document.forms [0]。长度= 3个 document.forms [1]。长度= 0 – user1314014 2012-04-05 09:32:07

回答

1

在用于显示在它的形式对话框jQuery的功能,我需要的是对话的内容添加到第二个网页上的表单如下:

$ 。( “#waterDialog”)母体()appendTo($( “形式”)当量(1)[0]);