我在表单上有两个电子邮件字段来验证用户是否正确输入了他的电子邮件。但是,即使正确输入了两次电子邮件,jquery.validate.unobtrusive也始终会显示错误消息。
这是一个ASP.Net MVC3项目,我在第二个电子邮件字段中使用了Compare属性。
以下是我的网页上该区域的html代码:
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-length="The field Adresse de courriel must be a string with a maximum length of 50." data-val-length-max="50" data-val-required="L&#39;adresse de courriel doit &#234;tre sp&#233;cifi&#233;e" id="Requerant_Individu_Courriel" name="Requerant.Individu.Courriel" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Requerant.Individu.Courriel" data-valmsg-replace="true"></span>
</div>
<div class="editor-field">
<input class="text-box single-line" data-val="true" data-val-equalto="Les deux adresses de courriel doivent &#234;tre identiques" data-val-equalto-other="*.Courriel" data-val-required="L&#39;adresse courriel de confirmation doit &#234;tre sp&#233;cifi&#233;e" id="Requerant_Individu_ConfirmCourriel" name="Requerant.Individu.ConfirmCourriel" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Requerant.Individu.ConfirmCourriel" data-valmsg-replace="true"></span>
</div>我在第二个电子邮件输入中注意到这个属性: data-val-equalto-other="*.Courriel“我想知道这个星号是否正确。
这是我的模型中的内容:
[Required(ErrorMessage = "L'adresse de courriel doit être spécifiée")]
[StringLength(50)]
[Display(Name = "Adresse de courriel")]
public String Courriel { get; set; }
[Compare("Courriel", ErrorMessage = "Les deux adresses de courriel doivent être identiques")]
[Required(ErrorMessage = "L'adresse courriel de confirmation doit être spécifiée")]
[Display(Name = "Retapez votre adresse de courriel")]
public string ConfirmCourriel { get; set; }有没有人遇到过这个问题?有什么建议吗?
注意:我使用的是jQuery 1.6.3和jQuery验证插件1.8.1
发布于 2011-09-09 06:11:41
我终于在这篇文章中找到了我问题的答案:
JQuery 1.5 breaks Compare Validate (JQuery Validate 1.8)
在文件jquery.validate.unobtrusive.js中,第288行:
element = $(options.form).find(":input[name=" + fullOtherName + "]")[0];必须替换为以下代码:
element = $(options.form).find(":input[name='" + fullOtherName.replace(".", "\\.").replace("[", "\\[").replace("]", "\\]") + "']")[0];309行也是这样:
return $(options.form).find(":input[name='" + paramName + "']").val();它必须被替换为:
return $(options.form).find(":input[name='" + paramName.replace(".", "\\.").replace("[", "\\[").replace("]", "\\]") + "']").val();发布于 2012-01-24 03:48:59
如果您使用的是最小化版本,请执行搜索/替换:
替换:
f = a(b.form).find(":input[name=" + d + "]")[0];通过以下方式:
f=a(b.form).find(":input[name='"+d.replace(".","\\.").replace("[","\\[").replace("]","\\]")+"']")[0];另外,请替换:
return a(b.form).find(":input[name='"+c+"']").val()通过以下方式:
return a(b.form).find(":input[name='"+c.replace(".","\\.").replace("[","\\[").replace("]","\\]")+"']").val()https://stackoverflow.com/questions/7354835
复制相似问题