基于http://foolproof.codeplex.com/SourceControl/latest#Foolproof/Client Scripts/mvcfoolproof.unobtrusive.js,您可以将自定义客户端验证规则添加为服务器端兄弟。
我在项目中所做的是扩展该文件的万无一失的基础。
示例代码:
(function () {
jQuery.validator.addMethod("foo", function (value, element, params) {
//validation code...
});
// code based on link
var setValidationValues = function (options, ruleName, value) {
options.rules[ruleName] = value;
if (options.message) {
options.messages[ruleName] = options.message;
}
};
var $Unob = $.validator.unobtrusive;
$Unob.adapters.add("foo", ["dependentproperty", "dependentvalue", ...(add more parameters if you want)], function (options) {
var value = {
dependentproperty: options.params.dependentproperty,
dependentvalue: options.params.dependentvalue,
};
setValidationValues(options, "foo", value);
});
})();
希望对你有帮助!