これには使用できません。編集タグのないビューでのみ使用List<album>
できます。1 つのビューが正常に機能していますが、それらの 1 つのリストを編集することはできません。
@model IEnumerable<MyMixtapezServerCodeHomePage.Models.album>
@using (Html.BeginForm("FeatureSystem", "album", FormMethod.Post))
{
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th>
@Html.DisplayNameFor(model => model.feature)
</th>
<th>
@Html.DisplayNameFor(model => model.feature_order)
</th>
<th></th>
</tr>
@foreach (var item in @Model)
{
<tr>
<td>
<div class="editor-label">
@Html.LabelFor(model => item.name)
</div>
<div class="editor-field">
@Html.EditorFor(model => item.name,"album")
@Html.ValidationMessageFor(model => item.name)
</div>
</td>
<td>
<div class="editor-label">
@Html.LabelFor(model => item.feature,"album")
</div>
<div class="editor-field">
@Html.EditorFor(model => item.feature)
@Html.ValidationMessageFor(model => item.feature)
</div>
</td>
<td>
<div class="editor-label">
@Html.LabelFor(model => item.feature_order)
</div>
<div class="editor-field">
@Html.EditorFor(model => item.feature_order,"album")
@Html.ValidationMessageFor(model => item.feature_order)
</div>
</td>
<td></td>
</tr>
}
<input type="submit" />
</table>}
コントローラ
[HttpPost]
public ActionResult FeatureSystem(IEnumerable<album> albums)
{
foreach (album album in albums)
{
if (ModelState.IsValid)
{
albumRepository.Update(album);
albumRepository.SaveChanges();
}
}
return RedirectToAction("Index");
}
アルバムが null であると受け取りました。なぜですか? 1 つのリストを編集できますか? これだけ必要です。