相关疑难解决方法(0)

具有前缀的控件的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" });
%>
Run Code Online (Sandbox Code Playgroud)

控件ViewUserControl <PhoneViewModel>:

<%= Html.TextBox(Model.GetPrefixed("CountryCode"), Model.Phone.CountryCode) %>
<%= Html.ValidationMessage("Phone.CountryCode", new { id = Model.GetPrefixed("CountryCode"), name = Model.GetPrefixed("CountryCode") })%>
Run Code Online (Sandbox Code Playgroud)

其中Model.GetPrefixed("CountryCode")只返回"FaxPhone.CountryCode"或"PhonePhone.CountryCode"取决于前缀


这是表单后生成的验证规则.它们被复制为字段名"Phone.CountryCode".虽然期望的结果是每个FieldNames"FaxPhone.CountryCode","PhonePhone.CountryCode" alt文本的 2个规则(必需,数量),但是 http://www.freeimagehosting.net/uploads/37fbe720bf.png

这个问题与Asp.Net MVC2客户端验证和重复ID的问题有些重复, 但建议手动生成ID并没有帮助.

validation client viewusercontrol prefixes asp.net-mvc-2

5
推荐指数
1
解决办法
1818
查看次数