Imports System.Collections.Generic
Imports Nancy.ModelBinding
Public Class ProductModule
MyBase.Get("/index") = Function(parameters)
Dim customers = GetCustomers()
MyBase.Post("/add") = Function(parameters)
Dim customer = Me.Bind(Of Customer)()
Dim result = Me.Validate(Of Customer)(customer)
Return RenderErrorView(result)
Dim customers = GetCustomers()
Private Function RenderErrorView(result As ModelValidationResult) As String
Dim url = string.Format("<a href='{0}'>Back to List</a>", Context.ToFullPath("~/index"))
Dim errorsDescription As List(Of String) = result.Errors.SelectMany(Function(e)
Return e.Value.Select(Function(err) err.ErrorMessage)
Return "Sorry, but your data is invalid. " + url + "<br/>Errors: <br/>" + String.Join(", <br/>", errorsDescription)
Private Function GetCustomers As List(Of Customer)
Dim customers as New List(Of Customer) From {New Customer With {.Id = 1, .Name = "John"}, New Customer With {.Id = 2, .Name = "Bob"}, New Customer With {.Id = 42, .Name = "Alice"}}