0
誰かが私のdropdownlistforが変更されない理由を知っていて、選択リストのオプションを変更したときに新しい値をコントローラにポストバックするのだろうかと思います。選択リストはforloop内にあり、複数の選択リストを持つ複数の項目を表示するので、ユーザーは選択した項目を新しい項目に変更できます。DropDownList新しい値を選択したときに選択した値を変更しない
@for (int i = 0; i < Model.PoItemsList.Count; i++)
{
net += Convert.ToDecimal(Model.PoItemsList[i].Net);
vat += Convert.ToDecimal(Model.PoItemsList[i].Vat);
gross += Convert.ToDecimal(Model.PoItemsList[i].Gross);
<tr>
<td>
@Html.HiddenFor(m => m.PoItemsList[i].Id)
@Html.HiddenFor(m => m.PoItemsList[i].NCodeId)
@Html.TextBoxFor(m => m.PoItemsList[i].ItemRef, new { @class = "form-control" })
</td>
<td>
@Html.TextBoxFor(m => m.PoItemsList[i].Description, new { @class = "form-control", @style = "width: 200px;" })
</td>
<td>
@*@Html.DropDownListFor(m => m.PoItemsList[i].NCodeId, Model.NominalCodeList, new { @class = "form-control", @id = "ncode" })*@
@Html.DropDownListFor(m => m.PoItemsList[i].NCodeId, new SelectList(Model.NominalCodeList, "Value", "Text", Model.PoItemsList[i].NCodeId), new { @class = "form-control"})
</td>
<td>
@Html.TextBoxFor(m => m.PoItemsList[i].CostPerItem, new { @class = "form-control", @Value = Convert.ToDecimal(Model.PoItemsList[i].CostPerItem) })
</td>
<td>
@Html.TextBoxFor(m => m.PoItemsList[i].Quantity, new { @class = "form-control", @style = "width: 50px;" })
</td>
<td>
@Html.TextBoxFor(m => m.PoItemsList[i].Net, new { @class = "form-control cpd-align-right", @Value = Convert.ToDecimal(Model.PoItemsList[i].Net) })
</td>
<td>
@Html.TextBoxFor(m => m.PoItemsList[i].Vat, new { @class = "form-control cpd-align-right", @Value = Convert.ToDecimal(Model.PoItemsList[i].Vat) })
</td>
<td>
@Html.TextBoxFor(m => m.PoItemsList[i].Gross, new { @class = "form-control cpd-align-right", @Value = Convert.ToDecimal(Model.PoItemsList[i].Gross) })
</td>
<td>
@Html.CheckBoxFor(m => m.ManualEntry, new {@class = "form-control"})
</td>
<td>
<input type="button" class="btn btn-danger centre" value="X" onclick="DeleteItemAndSave(@Model.PoItemsList[i].Id)" />
</td>
</tr>
}
PoitemsListの他のプロパティはポストバック時に適切に設定されますか? – Cizaphil
はい、私がpoitemlist eg.descriptionの中の何かを変更した場合、変更はコントローラの罰金にポストバックされます。 – user3481085
@Adeに従うストリンガーの答えと何が起こるかを確認 – Cizaphil