2012-08-23 29 views
1

我已經使用formbuilder創建了一個擴展。現在我已經在我看來使用它了。 我的看法是這樣的:如何在窗體中動態創建表單

@using (Html.BeginForm("addDataInd", "CustInformations", FormMethod.Post)) 
{ 
    <fieldset class="field"> 
    <legend>Addresses</legend> 
     <table> 
     <tr>        
      @Html.EditorFor(model => model.addresses) 
     </tr> 
     </table>   
    </fieldset> 
} 

其中

@Html.EditorFor(model=>model.addresses) 

叫我EditorTemplate它看起來像:

<td> 
@Html.hSearch("txtSearch", "", "lblsrch", "Search Text: ", "Search", "Fetch", "LookUp", new { script = "Select Aid, FullAreaName from fGetAreaTB()" }, null) 
</td> 

當我運行該程序的頁面看起來像

enter image description here

我用火蟲知道錯誤。我發現的唯一情況是,爲上面的圖片(即永久地址)生成的代碼不會創建表單,但對於其他兩個表單創建表單。所以當我點擊第一個搜索按鈕時,它不起作用,但是當我點擊第二個和第三個按鈕時,它運行良好。

我只是想當我運行程序時,所有的按鈕都必須在窗體中。

回答

2

您不能嵌套HTML表單。出於這個原因,你將不得不使用多種形式並將它們放入模板中。就像這樣:

<fieldset class="field"> 
    <legend>Addresses</legend> 
    <table> 
     <tr>        
      @Html.EditorFor(model => model.addresses) 
     </tr> 
    </table>   
</fieldset> 

和編輯模板中:

@model Address 
<td> 
    @using (Html.BeginForm("addDataInd", "CustInformations", FormMethod.Post)) 
    { 
     @Html.hSearch("txtSearch", "", "lblsrch", "Search Text: ", "Search", "Fetch", "LookUp", new { script = "Select Aid, FullAreaName from fGetAreaTB()" }, null) 
    } 
</td>