숨겨진 필드 목록 :MVC3 모델 바인딩 - 나는 독특한 문제가
@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])
}
이 폼 내부에 앉아있다 또한 - 폼이 제출 될 때, 유효성 검사 오류가 발생했을 경우, 일 e 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);
}
결과 HTML을 제공 할 수 있습니까? ? 나는 당신의 html 요소가 목록으로 인식 할 수없는 동일한 이름/id를 가지고 있지 않다고 의심하고있다. – Joakim
컨트롤러 작업을 게시 할 수 있습니까? – nemesv
게시자가 컨트롤러에 조치를 취합니다. – Carl