MVCには次のクラスレイアウトがあります。
public class ReportModel
{
List<SomeItem> items;
string value;
string anotherValue;
}
ここで、このタイプのMVCで厳密に型指定されたビューを作成し、編集可能なテキストフィールドを作成して各値を編集し、foreachループを使用してテキストフィールドにデータを入力して、アイテムのリスト内のアイテムを編集します。
httppostメソッドに送信すると、reportmodelオブジェクトで特異値が正常に返されますが、リストはオブジェクトで返されません。これはどのように行う必要がありますか?
私がhttppostと言うとき、私はMVCがポストバックしているメソッドを指します
[HttpPost]
public ActionResult EditReport(ReportModel report)
{
// Save the report in here after the update on the UI side
}
someitemのリストを投稿するためのコードを表示
if (Model.items != null && Model.items.Count > 0)
{
for (int i = 0; i < Model.items.Count; i++)
{
<div class="editrow">
<div class="edititem">
<div class="editor-label">
@Html.LabelFor(m => m.items.ElementAt(i).propertyOne)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.items.ElementAt(i).propertyOne)
@Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyOne)
</div>
</div>
<div class="edititem">
<div class="editor-label">
@Html.LabelFor(m => m.items.ElementAt(i).propertyTwo)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.items.ElementAt(i).propertyTwo)
@Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyTwo)
</div>
</div>
<div class="edititem">
<div class="editor-label">
@Html.LabelFor(m => m.items.ElementAt(i).propertyThree)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.items.ElementAt(i).propertyThree)
@Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyThree)
</div>
</div>
</div>
}
}