문제는 다음과 같습니다. 동일한 유형의 컨트롤 2 개를 페이지에 배치 할 때 바인딩에 대해 다른 접두사를 지정해야합니다. 이 경우 양식 바로 다음에 생성 된 유효성 검사 규칙이 잘못되었습니다. 그래서 경우?에 대한 클라이언트 검증 작업을하는 방법에접두사가있는 컨트롤의 Asp.Net MVC2 Clientside 유효성 검사 문제
페이지에는 다음이 포함
<%
Html.RenderPartial(ViewLocations.Shared.PhoneEditPartial, new PhoneViewModel { Phone = person.PhonePhone, Prefix = "PhonePhone" });
Html.RenderPartial(ViewLocations.Shared.PhoneEditPartial, new PhoneViewModel { Phone = person.FaxPhone, Prefix = "FaxPhone" });
%>
제어 ViewUserControl을 <PhoneViewModel> : Model.GetPrefixed("CountryCode")
그냥 "FaxPhone.CountryCode"를 반환
<%= Html.TextBox(Model.GetPrefixed("CountryCode"), Model.Phone.CountryCode) %>
<%= Html.ValidationMessage("Phone.CountryCode", new { id = Model.GetPrefixed("CountryCode"), name = Model.GetPrefixed("CountryCode") })%>
또는 "PhonePhone.CountryCode"(접두사에 따라 다름)
다음은 양식 다음에 생성 된 유효성 검사 규칙입니다. 필드 이름이 "Phone.CountryCode"인 경우 중복됩니다. 원하는 결과가이 지배하는 fieldName에 "FaxPhone.CountryCode"각각 (필수, 수), "PhonePhone.CountryCode" alt text http://www.freeimagehosting.net/uploads/37fbe720bf.png
하지만 문제는 다소 Asp.Net MVC2 Clientside Validation and duplicate ID's problem 의 중복되지만 조언 수동 식별자 아무튼 생성 도와 줘.
Nice. 이 대답은 매우 도움이되었습니다. 나는 그것을 두 번 더 upvote 수 있기를 바랍니다. –
매우 유용합니다. 고맙습니다. – Luke
나는 이것이 오래된 대답이라는 것을 알고 있지만, 당신의 방법이 당신의 시야에 놓이는 것이 더 바람직한 것인지 궁금해하고있다 : ViewData.TemplateInfo.HtmlFieldPrefix = "myViewModel.MyCustomObjdect"; –