Sorun şu: Bir sayfada aynı türde 2 denetim eklediğimde, farklı önek belirtmek zorundayım. Bu durumda, formdan sonra doğrulanan doğrulama kuralları yanlıştır. Yani durumda ?: için istemci doğrulama çalışmaları nasılAsp.Net MVC2 Önekler ile denetimlerle istemci kimlik doğrulaması sorunu
sayfa içerir:
<%
Html.RenderPartial(ViewLocations.Shared.PhoneEditPartial, new PhoneViewModel { Phone = person.PhonePhone, Prefix = "PhonePhone" });
Html.RenderPartial(ViewLocations.Shared.PhoneEditPartial, new PhoneViewModel { Phone = person.FaxPhone, Prefix = "FaxPhone" });
%>
kontrol ViewUserControl <PhoneViewModel>: Model.GetPrefixed("CountryCode")
sadece "FaxPhone.CountryCode" döndürür
<%= Html.TextBox(Model.GetPrefixed("CountryCode"), Model.Phone.CountryCode) %>
<%= Html.ValidationMessage("Phone.CountryCode", new { id = Model.GetPrefixed("CountryCode"), name = Model.GetPrefixed("CountryCode") })%>
veya
'a bağlı olarak "PhonePhone.CountryCode"Ve bu formdan sonra oluşturulan doğrulama kuralları. Onlar "Phone.CountryCode" alan adı için çoğaltılır. İstenen sonuç 2 kurallar FieldNames "FaxPhone.CountryCode" her biri için (gerekli, sayı), "PhonePhone.CountryCode" alt text http://www.freeimagehosting.net/uploads/37fbe720bf.png
iken soru biraz Asp.Net MVC2 Clientside Validation and duplicate ID's problem arasında çoğaltmak ancak tavsiye elle kimlikleri doesn oluşturmak için yardımcı olur.
Güzel. Bu cevap çok yardımcı oldu. Keşke bir kaç kez daha yapabilirim. –
Çok, çok yararlı. Teşekkür ederim. – Luke
Bunun eski bir yanıt olduğunu biliyorum, ancak yönteminizin bunu sizin görünümünüze koymaya tercih edip etmediğini merak ediyorum: ViewData.TemplateInfo.HtmlFieldPrefix = "myViewModel.MyCustomObjdect"; –