Form和文本框MVC4的一个提交按钮

时间:2014-06-18 11:05:46

标签: html asp.net-mvc-4 view

我正在使用MVC4。

我使用@using(Html.BeginForm)查看表单 但我想使用而不是 fieldset

视图看起来很棒但是我必须有提交按钮(在每个记录中),如我的代码所示。

  1. 我只想一个按钮提交?所以我试着把提交出来 (Html.BeginForm)然后它将无法正常工作!!?
  2. 我也有价格的文本框...我想要链接到相同的提交按钮
  3. 这是我的观点:

    <p>Enter the price please :</p>@Html.TextBox("price")
       <fieldset> 
         <legend></legend>
       <table>
         <tr>
            <th>
               Title1
            </th>
            <th>
               Title1 
            </th>
            <th>
               Title3 
            </th>
            <th>
               button
            </th>
         </tr>
    
    
    @using (Html.BeginForm("Action", "Contrroler"))
      { 
    
    int index = 0;
    
    
            foreach (var req in Model.SelectedHome.Descreption)
            {               
                 <tr>
                 <td>
                     @Html.DisplayFor(m => m.homenmae)
    
                </td> 
    
                 <td>
                     @Html.DisplayFor(m => m.place)
    
                </td> 
                 <td>
                     @Html.EditorFor(m => m.rommsnumber)
    
                </td> 
                 <td>
                     <button type="submit" class="button "> click </button>
                 <td>
                    </tr> 
    
    
                index++;
            }
    
     } 
     </table>
    
    
     </fieldset>    
    

2 个答案:

答案 0 :(得分:1)

如果没有其他代码,您无法使用提交按钮提交表单

     @using (Html.BeginForm("Action", "Contrroler", FormMethod.Post, new {id='myForm'} ))
          { 

<p>Enter the price please :</p>@Html.TextBox("price")
   <fieldset> 
     <legend></legend>
   <table>
     <tr>
        <th>
           Title1
        </th>
        <th>
           Title1 
        </th>
        <th>
           Title3 
        </th>
        <th>
           button
        </th>
     </tr>



        int index = 0;


                foreach (var req in Model.SelectedHome.Descreption)
                {               
                     <tr>
                     <td>
                         @Html.DisplayFor(m => m.homenmae)

                    </td> 

                     <td>
                         @Html.DisplayFor(m => m.place)

                    </td> 
                     <td>
                         @Html.EditorFor(m => m.rommsnumber)

                    </td> 

                 </tr> 

                    index++;
                }
        }
    </table>

    <button id='submitForm'>Submit</button>

JS:

$('#submitForm').click(function(){
    $('#myForm').submit();
});

答案 1 :(得分:0)

将提交按钮放在for循环之外,但在表单

相关问题