独特の問題があります-画像のリストを表示するために使用されるリストを含むViewModelがあります:
public List<int> TrackerKeys { get; set; }
これは、ページ内の 2 つの場所で使用されます。
@for (int i = 0; i < Model.TrackerKeys.Count(); i++)
{
@Html.GenerateImage(PageModes.Http, Model.TrackerKeys[i])
}
また、
@for (int i = 0; i < Model.TrackerKeys.Count(); i++)
{
@Html.HiddenFor(model => model.TrackerKeys[i])
}
これはフォーム内に置かれます。フォームが送信されると、検証エラーが発生すると、TrackerKeys プロパティが新しいランダムな数値セットで更新されます。ユーザーに同じ画像が再び表示されないように、以前のリストを渡しています。
トラッカー キーが正しく設定され、ビューに戻されます。
私の問題は次のとおりです。
イメージは、リスト内の新しい値に基づいて新しいイメージを正しく表示します
でも
非表示フィールドの値は新しい値に更新されず、元の値が保持されます。
何か案は?これは MVC3 のバグですか? 任意の入力をいただければ幸いです。ありがとうございました。
編集
送信前の HTML:
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/26.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/33.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/8.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/30.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/6.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/18.gif" width="35" />
と
<input id="TrackerKeys_0_" name="TrackerKeys[0]" type="hidden" value="26" />
<input id="TrackerKeys_1_" name="TrackerKeys[1]" type="hidden" value="33" />
<input id="TrackerKeys_2_" name="TrackerKeys[2]" type="hidden" value="8" />
<input id="TrackerKeys_3_" name="TrackerKeys[3]" type="hidden" value="30" />
<input id="TrackerKeys_4_" name="TrackerKeys[4]" type="hidden" value="6" />
<input id="TrackerKeys_5_" name="TrackerKeys[5]" type="hidden" value="18" />
そして投稿後:ここで新しい値を修正してください...
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/16.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/20.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/11.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/19.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/26.gif" width="35" />
<img alt="Security Character" height="35" src="http://localhost:51414/content/imagescss/15.gif" width="35" />
そして...まだ古い値を保持しています...
<input id="TrackerKeys_0_" name="TrackerKeys[0]" type="hidden" value="26" />
<input id="TrackerKeys_1_" name="TrackerKeys[1]" type="hidden" value="33" />
<input id="TrackerKeys_2_" name="TrackerKeys[2]" type="hidden" value="8" />
<input id="TrackerKeys_3_" name="TrackerKeys[3]" type="hidden" value="30" />
<input id="TrackerKeys_4_" name="TrackerKeys[4]" type="hidden" value="6" />
<input id="TrackerKeys_5_" name="TrackerKeys[5]" type="hidden" value="18" />
コントローラーアクション
[HttpPost]
public ActionResult EmployerRegistration(EmployerViewModel Model)
{
if (ModelState.IsValid)
{
//do bits here
}
Model.TrackerKeys = Helper.GenerateNewNumbers(Model.TrackerKeys);
return View(Model);
}