Created
November 12, 2012 20:38
-
-
Save prabirshrestha/4061724 to your computer and use it in GitHub Desktop.
nancy model binding and validation example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SampleModule : NancyModule { | |
| public SampleModule() { | |
| Post["/"] = x => { | |
| var person = this.Bind<Person>(); | |
| this.Validate(person); | |
| if(!this.ModelValidationResult.IsValid) | |
| return 400; | |
| return 200; | |
| } | |
| } | |
| } | |
| public class Person { | |
| public string FirstName {get; set; } | |
| } | |
| public class PersonValidatior : AbstractValidator<Person> { | |
| public PersonValidatior() { | |
| RuleFor(m => m.FirstName).NotEmpty().WithMessage("First name required"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment