我在南希有示例应用程序,但请求验证有问题。
我正在使用带有 BindAndValidate 扩展的 FluentValidator。所以例如我有模型:
public class User
{
public string Name { get; set; }
public int Age { get; set; }
}
和模块:
Post["/create-user"] = m => this.BindAndValidate<User>());
还有一个问题,如果客户端应用程序调用带有参数 Name:"foo, Age:"some-string" 的模块,那么 Nancy 会抛出异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: some-string is not a valid value for Int32. ---> System.FormatException: Input string was not in a correct format.
这里是否有任何参数异常的解决方法(“属性年龄的格式不正确”)?
谢谢