2013-12-19 19 views
0

我有一個場景,我已經加載數據的下拉選擇更改和操作後,我必須提交頁面進行保存。在MVC中使用嵌套的beginform

我已經開發了這個頁面,但是因爲我是新來的MVC,所以任何人都可以驗證我的代碼,並且可以建議更好的方法來做同樣的事情。

@using (Html.BeginForm("Save", "forecast")) 
{ 
    using (Html.BeginForm("YearChange", "forecast", FormMethod.Get, new {@id="frmYearChange" })) 
    { 
     <div class="span12"> 
      <div class="well well-sm" style="padding-bottom: 0px !important;"> 
       <div class="span5"> 
        <div class="control-group"> 
         <label class="control-label" for="selectGroup"> 
          Select Group:</label> 
         <div class="controls"> 
          @Html.DropDownListFor(m => m.groupId, Model.groupList, "--Select Group--", new { @id = "selectGroup" }) 
         </div> 
        </div> 
       </div> 
       <div class="span5"> 
        <div class="control-group"> 
         <label class="control-label" for="selectYear"> 
          Select Year:</label> 
         <div class="controls"> 
          @Html.DropDownListFor(m => m.yearId, Model.yearList, "--Select Year--", new { @id = "selectYear", onchange = "selectYear_indexChanged();" }) 
         </div> 
        </div> 
       </div> 
       <div class="clearfix"> 
        &nbsp;</div> 
      </div> 
     </div> 
    } 
..... 
} 
+6

我不認爲你可以有嵌套形式 [檢查此鏈接] [1] [1]:http://stackoverflow.com/questions/379610/can-you -nest-html-forms – mattematico

+0

你可以有兩個頁面,一個是下拉菜單,當提交時,返回第二個頁面/表單。或者,在提交下拉值時,您執行AJAX提交併將當前表單替換爲返回包含第二個表單的PartialView的操作的結果,或者用新表單替換當前表單下方的div佔位符,以便您有兩個形式在上面/下面而不是嵌套。 – AaronLS

回答

1

您不能有嵌套窗體。但是,您可以爲每個視圖製作多個表單。 有關更多信息,請參見W3C