Angular with .NET WebAPI validation, and single-point-of-truth

后端 未结 1 1054
孤城傲影
孤城傲影 2021-02-02 03:23

Is there an approach that preserves the single-definition of validation, allows immediate client-side validation, and still provides the strength of server-side validation?

1条回答
  •  [愿得一人]
    2021-02-02 04:01

    The approach I recommend is based on @Esteban Felix commented and I used similar strategy in Java/Bean Validation and JSON schema generator.

    Annotate your Domain model using Validate Model Data Using DataAnnotations

    Generate schema using JSON.net other useful links

    Create a AutoValidate directive that goes on and decorate fields with AngularJS build in directives for form validation e.g. ngPattern and simple things like min/max. In my case I created a mapping from Java world to AngularJS directives and wherever I needed we created custom directives.

    0 讨论(0)
提交回复
热议问题