Note that there are some explanatory texts on larger screens.

plurals
  1. POadd mvc3 Unobtrusive validation Min/max validators
    text
    copied!<p>I'm trying to implement client validation for my custom type, however i'm not sure how to do it for min/max validators.</p> <p>model:</p> <pre><code>[MultilanguagePropertyRequired(ErrorMessageResourceName = "fld_Description_val_Required", ErrorMessageResourceType = typeof(Resources.Service.Controllers.Firm))] [MultilanguagePropertyStringLength(1000, MinimumLength = 150, ErrorMessageResourceName = "fld_Description_val_MinLength_lbl", ErrorMessageResourceType = typeof(Resources.Service.Controllers.Firm))] [Display(Name = "fld_Description_lbl", ResourceType = typeof(Resources.Service.Controllers.Firm))] public MultilanguageProperty&lt;string&gt; Description { get { return this.GetMultilanguageProperty("Description", string.Empty, this); } set { this.SetMultilanguageProperty("Description", value); } } </code></pre> <p>this is my custom string length attribute that extends "StringLegth":</p> <pre><code>[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true)] public class MultilanguagePropertyStringLengthAttribute : StringLengthAttribute, IClientValidatable { public MultilanguagePropertyStringLengthAttribute(int length) : base(length) { } public override bool IsValid(object value) { string strValue = (string)(value as MultilanguageProperty&lt;string&gt;).Value; return base.IsValid(strValue); } public IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { yield return new ModelClientValidationRule() { ValidationType = "multilanguagestringlength", ErrorMessage = this.ErrorMessageString }; } } </code></pre> <p>then on my view I have this: ..</p> <pre><code>&lt;script type="text/javascript"&gt; (function ($) { $.validator.unobtrusive.adapters.addBool("multilanguagerequired", "required"); $.validator.unobtrusive.adapters.addMinMax("multilanguagestringlength", "minlength", "maxlength"); } (jQuery)); &lt;/script&gt; </code></pre> <p>..</p> <p>which doesn't work. am i missing something here? thanks</p>
 

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