using System.Collections.Generic;
using Nancy.ModelBinding;
public class CustomerModule : NancyModule
Get["/index"] = parameters =>
var customers = GetCustomers();
Post["/add"] = parameters =>{
var customer = this.Bind<Customer>();
var result = this.Validate<Customer>(customer);
return RenderErrorView(result);
var customers = GetCustomers();
private string RenderErrorView(ModelValidationResult result)
var url = string.Format("<a href='{0}'>Back to List</a>", this.Context.ToFullPath("~/index"));
e.Value.Select(error => error.ErrorMessage)).ToList();
return "Sorry, but your data is invalid. " + url + "<br/>Errors: <br/>" +
string.Join(", <br/>", errorsDescription);
private List<Customer> GetCustomers()
return new List<Customer>()