2014-03-13 42 views
1

我有其定義表中的一行作爲下一個局部視圖:從局部視圖使用jquery + Ajax的MVC添加新行4 .NET

@model CarpetApp.Models.OrderDetails 
<script src="~/Scripts/jquery-1.7.1.min.js"></script> 
<script src="~/Scripts/jquery.validate.min.js"></script> 
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> 

@using (Html.BeginCollectionItem("OrderDetails")) 
{ 
    <tr> 
     <td>@Html.EditorFor(model => model.RunningNO)</td> 
     <td>@Html.EditorFor(model => model.ProjectReference)</td> 
     <td>@Html.DropDownListFor(model => model.DesignId, Model.design)</td> 
     <td>Quality Dropdown List</td> 
     <td>@Html.ListBoxFor(model => model.SelectBackGround, Model.BackGround)</td> 
     <td>@Html.ListBoxFor(model => model.SelectedMotif, Model.Motif)</td> 
     <td>@Html.DropDownListFor(model => model.measurement, Model.mesurements)</td> 
     <td>@Html.EditorFor(model => model.WidthIntPart)</td> 
     <td>@Html.EditorFor(model => model.WidthDecPart)</td> 
     <td>@Html.EditorFor(model => model.LengthInt)</td> 
     <td>@Html.EditorFor(model => model.LengthDec)</td> 
     <td>@Html.EditorFor(model => model.Area)</td> 
     <td>@Html.EditorFor(model => model.Remark)</td> 
    </tr> 
} 

此外,我試圖加載這些行插入到如下表所示:

<table id="tabletab" width="100%"> 
    <tr> 
     <th rowspan="2">Running No</th> 
     <th rowspan="2">Project Ref</th> 
     <th rowspan="2">Design</th> 
     <th rowspan="2">Quality</th> 
     <th colspan="2">Color</th> 
     <th rowspan="2">Measurement Unit</th> 
     <th rowspan="2" colspan="2">Width</th> 
     <th rowspan="2" colspan="2">Length</th> 
     <th rowspan="2">Area</th> 
     <th rowspan="2">Remarks</th> 
    </tr> 
    <tr> 
     <th>Background</th> 
     <th>Motif</th> 
    </tr> 
</table> 

我使用Ajax調用加載的局部視圖:

  $(function() { 
      $("#addAnother").click(function() { 
       event.preventDefault(); 
       $.get('/Order/AddOrder', function (template) { 
        $("#tabletab").append(template); 
       }); 
      }); 
     }); 

然而,這個問題我通過Ajax調用返回部分視圖,但不與調用ajax函數的視圖中定義的表列對齊。相反,結果只是加載到一個列中。

我可以類似地加載預定義在ajax本身的html,並且網絡中的各種解決方案也存在。但是,我無法加載上面局部視圖中定義的行。特別加載局部視圖使用

@Html.Action("AddOrder") 

然而,按需要工作。

幫助將不勝感激。

回答

0

我和我的項目有同樣的問題。在部分嘗試將開始收藏放入<tr>

<tr> 
    @using (Html.BeginCollectionItem("OrderDetails")) 
    { 
    <td>@Html.EditorFor(model => model.RunningNO)</td> 
    <td>@Html.EditorFor(model => model.ProjectReference)</td> 
    <td>@Html.DropDownListFor(model => model.DesignId, Model.design)</td> 
    <td>Quality Dropdown List</td> 
    <td>@Html.ListBoxFor(model => model.SelectBackGround, Model.BackGround)</td> 
    <td>@Html.ListBoxFor(model => model.SelectedMotif, Model.Motif)</td> 
    <td>@Html.DropDownListFor(model => model.measurement, Model.mesurements)</td>   
    <td>@Html.EditorFor(model => model.WidthIntPart)</td> 
    <td>@Html.EditorFor(model => model.WidthDecPart)</td> 
    <td>@Html.EditorFor(model => model.LengthInt)</td> 
    <td>@Html.EditorFor(model => model.LengthDec)</td> 
    <td>@Html.EditorFor(model => model.Area)</td> 
    <td>@Html.EditorFor(model => model.Remark)</td>} 
</tr> 

好運