Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created November 12, 2012 20:38
Show Gist options
  • Save prabirshrestha/4061724 to your computer and use it in GitHub Desktop.
Save prabirshrestha/4061724 to your computer and use it in GitHub Desktop.
nancy model binding and validation example
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