Custom Validation no client side validation

Apr 3, 2013 at 3:08 PM
Edited Apr 3, 2013 at 3:08 PM
Hello all,

I tried to implement the example in

http://www.nickriggs.com/posts/build-model-aware-custom-validation-attributes-in-asp-net-mvc-2/

But the custom client side validation is not happening.

I am using MVC 4.0.

I have used @Scripts.Render("~/Scripts/mvcfoolproof.unobtrusive.min.js") in my View.

Please advise on what m I missing.

Thanks in advance.
Apr 22, 2013 at 12:53 PM
With MVC4 there is an interface which has to be implemented which isn't implemented within foolproof, I have created my own subset of annotations based upon the very good foolproof code which does implement the interface and this works perfectly with mvcfoolprooj.unobtrusive.js. The interface is IClientValidatable.
public abstract class ModelAwareAttribute : ValidationAttribute, IClientValidatable
{
  //...
  public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
  {
    yield return new ModelClientValidationRule()
    {
      ErrorMessage = ErrorMessage,
      ValidationType = "is"
    };
  }
}