.NET plugin for valdr, an AngularJS model validator.
- Offering
- Installation
- Dependencies
- Mapping of .NET DataAnnotations attributes to valdr constraints
- License
valdr .NET parses C# classes for DataAnnotation attributes and extracts their information into a JavaScript file, which includes the metadata to be used by valdr. This allows to apply the exact same validation rules on the server and on the AngularJS client.
To install the Nuget package, run the following command in the Package Manager Console:
PM> Install-Package Nca.Valdr
In Visual Studio, right-click your project and under Properties/Build Events add the following Post-build event:
$(SolutionDir)packages\Nca.Valdr.1.1.1\tools\Nca.Valdr.Console.exe -i:$(TargetDir)$(TargetFileName) -o:$(ProjectDir)app\app.valdr.js
Nca.Valdr.exe accepts the following parameters:
-i:
input assembly filename (.dll)-n:
namespace filter (default: all)-o:
output JavaScript filename-a:
AngularJS application name (default: "app")-c:
Culture (optional, e.g. "en" or "en-US")
valdr .NET Validation is dependent on valdr in two ways:
- JSON structure is defined by valdr
- validators listed in the JSON document have to be either a supported valdr valdidator or one of your custom JavaScript validators
Only C# classes decorated with a DataContract attribute will be used the generate the valdr metadata.
The .NET DataAnnotations attributes defines the mapping of .NET Validation to valdr constraints.
.NET DataAnnotations | valdr | Comment |
---|---|---|
Required | required | |
Range | min | |
Range | max | |
StringLength | size | |
digits | unsupported | |
RegularExpression | pattern | |
future | unsupported | |
past | unsupported | |
EmailAddress | ||
URL | url |
MIT © Netcetera AG