mvc3数据验证问题CompareAttribute
为什么客户端不验证compare,看生成的脚本也有生成相关的验证代码,其它的会验证,我未使用unobtrusive,<addkey="ClientValidationEn...
为什么客户端不验证compare,看生成的脚本也有生成相关的验证代码,其它的会验证,我未使用unobtrusive,
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="false" />
[Required(ErrorMessage = "新密码不能为空")]
[Display(Name = "新密码")]
[StringLength(20, MinimumLength = 6, ErrorMessage = "新密码最小6个字符")]
public string NewPassword { get; set; }
[Required(ErrorMessage = "确认密码不能为空")]
[Display(Name = "确认密码")]
[Compare("NewPassword", ErrorMessage = "两次密码不相同")]
public string ConfirmPassword { get; set; }
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }
window.mvcClientValidationMetadata.push({"Fields":
[{"FieldName":"NewPassword","ReplaceValidationMessageContents":true,"ValidationMessageId":"NewPassword_validationMessage","ValidationRules":
[{"ErrorMessage":"新密码最小6个字符","ValidationParameters":
{"min":6,"max":20},"ValidationType":"length"},{"ErrorMessage":"新密码不能为
空","ValidationParameters":{},"ValidationType":"required"}]},
{"FieldName":"ConfirmPassword","ReplaceValidationMessageContents":true,"ValidationMessageId":"ConfirmPassword_validationMessage","ValidationRules":
[{"ErrorMessage":"两次密码不相同","ValidationParameters":
{"other":"*.NewPassword"},"ValidationType":"equalto"}, 展开
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="false" />
[Required(ErrorMessage = "新密码不能为空")]
[Display(Name = "新密码")]
[StringLength(20, MinimumLength = 6, ErrorMessage = "新密码最小6个字符")]
public string NewPassword { get; set; }
[Required(ErrorMessage = "确认密码不能为空")]
[Display(Name = "确认密码")]
[Compare("NewPassword", ErrorMessage = "两次密码不相同")]
public string ConfirmPassword { get; set; }
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }
window.mvcClientValidationMetadata.push({"Fields":
[{"FieldName":"NewPassword","ReplaceValidationMessageContents":true,"ValidationMessageId":"NewPassword_validationMessage","ValidationRules":
[{"ErrorMessage":"新密码最小6个字符","ValidationParameters":
{"min":6,"max":20},"ValidationType":"length"},{"ErrorMessage":"新密码不能为
空","ValidationParameters":{},"ValidationType":"required"}]},
{"FieldName":"ConfirmPassword","ReplaceValidationMessageContents":true,"ValidationMessageId":"ConfirmPassword_validationMessage","ValidationRules":
[{"ErrorMessage":"两次密码不相同","ValidationParameters":
{"other":"*.NewPassword"},"ValidationType":"equalto"}, 展开
展开全部
少了脚本是不行的
<script src="../../Scripts/jquery-1.8.3.js"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Scripts/jquery-1.8.3.js"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
追问
compare必须要使用unobtrusivejs吗
追答
嗯,就是这个脚本支持验证和交互的。 不然mvc怎么知道你输入了什么
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询