具有前缀的控件的Asp.Net MVC2 Clientside验证问题
问题是:当我在页面上放置2个相同类型的控件时,我需要为绑定指定不同的前缀。在这种情况下,在表单不正确之后生成的验证规则。那么如何让客户端验证工作呢?
该页面包含:
<%
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&lt; PhoneViewModel&gt;:
<%= Html.TextBox(Model.GetPrefixed("CountryCode"), Model.Phone.CountryCode) %>
<%= Html.ValidationMessage("Phone.CountryCode", new { id = Model.GetPrefixed("CountryCode"), name = Model.GetPrefixed("CountryCode") })%>
其中Model.GetPrefixed("CountryCode")
只返回“FaxPhone.CountryCode”或“PhonePhone.CountryCode”,具体取决于前缀
这是表单后生成的验证规则。它们被复制为字段名“Phone.CountryCode”。虽然所需的结果是每个FieldNames“FaxPhone.CountryCode”,“PhonePhone.CountryCode”的2个规则(必需,数量)
alt text http://www.freeimagehosting.net/uploads/37fbe720bf.png
问题与Asp.Net MVC2客户端验证和重复ID问题有些重复
但建议手动生成ID并没有帮助。
没有找到相关结果
已邀请:
1 个回复
磐乓铝举
哪里
(偶然发现Steve Sanderson博客上的代码中的解决方案http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/) 看起来像Html.EditorFor方法应该像以下建议一样工作:ASP.NET MVC 2 - ViewModel Prefix