Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.modelclientvalidationrule.validationparameters.aspx" rel="noreferrer"><code>ValidationParameters</code></a> property to add custom parameters to the rule:</p> <pre><code>public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { var rule = new ModelClientValidationRule { ErrorMessage = this.ErrorMessage, ValidationType = "futuredate", }; rule.ValidationParameters.Add("param1", "value1"); rule.ValidationParameters.Add("param2", "value2"); yield return rule; } </code></pre> <p>which could be used in the adapter:</p> <pre><code>jQuery.validator.unobtrusive.adapters.add( 'futuredate', [ 'param1', 'param2' ], function (options) { var param1 = options.params.param1; // shall equal 'value1' var param2 = options.params.param2; // shall equal 'value2' // TODO: use those custom parameters to define the client rules } ); </code></pre> <hr> <p>UPDATE:</p> <p>As requested in the comments section here's how you could pass those parameters to the custom validator rule function:</p> <pre><code>jQuery.validator.unobtrusive.adapters.add( 'futuredate', [ 'param1', 'param2' ], function (options) { // simply pass the options.params here options.rules['greaterThan'] = options.params; options.messages['greaterThan'] = options.message; } ); jQuery.validator.addMethod('greaterThan', function (value, element, params) { // params here will equal { param1: 'value1', param2: 'value2' } return ... }, ''); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload