Custom DataAnnotations Validator Derived from RegularExpressionAttribute

前端 未结 2 503
醉酒成梦
醉酒成梦 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 03:20

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

    DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(NameAttribute), typeof(RegularExpressionAttributeAdapter));
    

提交回复
热议问题