複数のジャーナルエントリ(各ジャーナルごとに1つ)を同時に更新(作成/編集)できるビューを作成したいとします。リストプロパティの複数のインラインフォームを作成する方法
のViewModel:
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; }
のリストを持っているジャーナルが1つ(またはを持っていますなし)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>
あなたのコントローラPOSTメソッドをポストする – User3250