にアレイ上の読み取り専用でありますFruitBox
は1〜3の間で指定できます。BoxLabels
、それ以上はありません。これを強制するには、List
の代わりにを使用すると思いました。コレクションは、私はこのようになりますMVCのViewModelを持っているViewModelに
私は、ページ上の私の入力を処理する私のかみそりビューでループを持っている:私はフォームを送信すると、私はエラーと死の黄色の画面(YSOD)を取得
@for(var i = 0; i < 3; i++)
{
@Html.LabelFor(model => Model.BoxLabels[i].SkuCode)
@Html.EditorFor(m => Model.BoxLabels[i].SkuCode, new { htmlAttributes = new { @class = "form-control" } })
}
:
Collection is read-only.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: Collection is read-only.
ViewModelなどで配列を使用しないでください。
'BoxLabel'と' BoxLabelViewModel'の定義は何ですか? – Jure
1つは私が修正したタイプミスで、今は 'BoxLabelViewModel'のコードを追加しました – Ciwan
1つの最適化提案。 'for'ステートメントに 'Model.Boxlabels.Length'(または' Count')を使用してください。固定された番号3ではなく、項目数を変更する場合は2つの場所で番号を編集する必要はありません。 – Jure