2017-05-09 46 views
0

我想创建一个视图,用户可以同时更新(创建/编辑)多个日记帐分录(每个日记帐一个)。如何为列表属性创建多个联机表格

视图模型:

public class CompanyRecoMonthViewModel 
{ 
    public Company Company { get; set; } 
    public string RecoMonth { get; set; } 
} 

公司拥有期刊的名单:

public virtual IList<Journal> Journals { get; set; } 

每个杂志有JournalEntries

public IList<JournalEntry> JournalEntries { get; set; } 

在每个月的名单杂志将有一个(或无)JournalEntry。

从控制器中,我将日志加载到视图中。

现在在视图中的代码。我试图将内联表单放入表格视图中。 我的问题是,在提交表单时,没有任何值被捕获。

可能没有正确使用@ Html.BeginForm。似乎表单不知道它要编辑哪个对象。

<table class="table"> 
    <tr> 
     <th> 
      Person Responsible 
     </th> 
     <th> 
      Journal Number 
     </th> 
     <th> 
      SomeID 
     </th> 
     <th> 
      Status 
     </th> 
     <th> 
      Upload Date 
     </th> 
     <th> 
      Amount< 
     </th> 
     <th></th> 
    </tr> 

    @foreach (var item in Model.Company.Journals) 
    { 
     <tr> 
      <td> 
       @Html.DisplayFor(modelItem => item.User.Name) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.JournalNumber) 
      </td> 

      <!-- this is where we start inline form for Journal Entry--> 
      @using (Html.BeginForm("Edit", "JournalEntries", FormMethod.Post, new { enctype = "multipart/form-data" })) 
      { 
       @Html.AntiForgeryToken() 
       <form class="form-inline"> 
        @Html.HiddenFor(modelItem => item.JournalID) 

        <div class="form-group"> 
         <td> 
          @Html.TextBoxFor(modelItem => item.JournalEntries[0].SomeID, new { @class = "form-control", maxlength = "8" }) 
         </td> 
         <td> 
          @Html.DropDownListFor(modelItem => item.JournalEntries[0].Status, Model.JournalStatuses.Select(e => new SelectListItem { Text = e }), string.Empty, new { @class = "form-control" }) 
         </td> 
         <td> 
          @Html.EditorFor(modelItem => item.JournalEntries[0].DatePosted, new { htmlAttributes = new { @class = "form-control datepicker" } }) 
         </td> 
         <td> 
          @Html.DropDownListFor(modelItem => item.JournalEntries[0].JournalType, Model.JournalTypes.Select(e => new SelectListItem { Text = e }), string.Empty, new { @class = "form-control" }) 
         </td> 
         <td> 
          @Html.EditorFor(modelItem => item.JournalEntries[0].AmountPosted, new { htmlAttributes = new { @class = "form-control" } }) 
         </td> 

         <td> 
          <button type="submit" class="btn btn-default">Save</button> 
         </td> 
        </div> 
       </form> 
      } 

     </tr> 
    } 

</table> 
+0

请发布您的控制器POST方法 – User3250

回答

0

设法实现对于每个局部视图对一个实体使用内联表单的多个部分视图。

0

添加虚拟关键字JournalEntries财产在你的日记类导航到JournalEntry的类。

public virtual IList<JournalEntry> JournalEntries { get; set; }