2011-07-03 56 views
0

我有一個表單,它有一些字段。我想在用戶在表單字段之一的文本框中輸入數字時顯示一些標籤。 我知道我必須使用Ajax,但問題在於Ajax表單處於另一種形式。因此,當我提交Ajax表單時,表單提交併且我無法獲取Ajax請求。 這裏是我的代碼結構:在MVC3中提交Ajax表單

@using (Html.BeginForm()) { 
@Html.ValidationSummary(true) 
<fieldset style="font-family:'B Nazanin';font-size:14pt"> 
    <div align="center">   
     <table border="0"> 
      <tr align="center"> 
       <td> 
        @Html.LabelFor(model => model.a) 

       </td> 
       <td> 
        @Html.LabelFor(model => model.a) 
        @Html.EditorFor(model => model.a) 
        @Html.ValidationMessageFor(model => model.a) 
       </td> 
      </tr> 
     </table> 
     <div align="right" id="searchJustForm"> 
     <fieldset style="font-family:'B Nazanin';font-size:14pt">        
      @using (Ajax.BeginForm("Index", "Terminal", new AjaxOptions() { UpdateTargetId = "divGomrokJust", InsertionMode = InsertionMode.Replace })) 
      { 
      <div align="center"> 

感謝你們的關注。

+4

HTML中嵌套的'form'元素是非法的。 –

回答

3

您不能嵌套HTML表單。這是無效的HTML。你將不得不修改你的標記。您可以通過訂閱.change表單元素的事件來使用純jQuery,並使用$.ajax方法觸發AJAX請求。

0

使用jQuery庫(www.jquery.com)中的$ .post Javascript函數將是最佳解決方案