2013-10-24 56 views
0

我有一個Html表單,它有一個提交按鈕,在表單內部,我有多個部分需要單獨提交。由於Html不支持嵌套表單,我該如何解決它?並且每個部分都需要在提交之前進行驗證。如何提交一個在asp.net中的另一個表單內的表單mvc

<% using (Html.BeginForm("actionName", "controllerName", FormMethod.Post)) 
     { %> 
<form id="frmHomeContact" method="post" > 
         -- a partial view is rendered here 
         <div class="grid-2-12"> 

          <input style="width: 100%;" type="button" title="save" value="save" /> 
         </div> 
         </form> 

<%}%> 

讓我知道如果問題不清楚。

+0

'jQuery.post()'=) – DontVoteMeDown

回答

1
$('#frmHomeContact').on('submit', function(){ 
    var $this = $(this); // catch a reference to the form 
    $.ajax({ 
     url: '/', //this should probably be the path to your controller 
     type: 'POST', 
     data: $this.serialize(), //name=George&msg=hello..etc <--note $this not $(this) 
     success: function(){ 
      console.log('Successful submission.'); 
     } 
    }); 
    return false; //submitting the form will no longer cause the browser to refresh. 
}); 
+0

按鈕類型是否應該「提交」?我試過,但沒有工作。 –

+0

你有什麼版本的jQuery?這需要1.7,使用'$('#frmHomeContact')。submit('如果您使用的版本低於1.7 – Ohgodwhy

+0

我正在使用jquery 1.8.3 –

0

的HTML代碼如下所示:

<% using (Html.BeginForm("actionName", "controllerName", FormMethod.Post),new { id = "frmHomeContact" }) 
     { %> 
<form method="post" > 
         -- a partial view is rendered here 
         <div class="grid-2-12"> 

          <input style="width: 100%;" type="button" title="save" value="save" /> 
         </div> 
         </form> 
<%}%> 
<script type="text/javascript"> 
    $("#frmHomeContact").submit(function() { 
    var $this = $(this); // catch a reference to the form 
     $.ajax({ 
      url: '/', //this should probably be the path to your controller 
      type: 'POST', 
      data: $this.serialize(), //name=George&msg=hello..etc <--note $this not $(this) 
      success: function(){ 
       alert('Successful submission.'); 
      } 
     }); 
     return false; //submitting the form will no longer cause the browser to refresh. 
    }); 
</script> 

您可以通過使用var txtname= $('#txtid').val();獲得單獨的文本框的值,並檢查TXT名稱是否爲空。

+0

我希望你錯了。'frmHomeContact'是內部形式的id。 –

相關問題