Custom DataAnnotations Validator Derived from RegularExpressionAttribute

前端 未结 2 504
醉酒成梦
醉酒成梦 2021-01-13 02:46

The Gu provides an example of how you might create a custom validator that overrides RegularExpressionAttribute .

The advantage of this is that you don\'t have to cr

相关标签:
2条回答
  • 2021-01-13 02:54

    If u wanna a client validation, you should Register a server-side adapter for remote validation.

    See here: http://msdn.microsoft.com/en-us/magazine/ee336030.aspx

    and here: http://bradwilson.typepad.com/blog/2010/01/remote-validation-with-aspnet-mvc-2.html

    0 讨论(0)
  • 2021-01-13 03:20

    Cracked it! Add the following to Global.asax.cs Application_Start()

    DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(NameAttribute), typeof(RegularExpressionAttributeAdapter));
    
    0 讨论(0)
提交回复
热议问题