【发布时间】:2014-09-13 18:16:53
【问题描述】:
我在 Nancy 有示例应用,但请求验证有问题。
我正在使用带有 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"的模块, 然后南希抛出异常:
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.
这里是否有任何参数异常的解决方法(“属性年龄格式不正确”)?
谢谢
【问题讨论】:
-
看起来今天这里有很好的记录github.com/NancyFx/Nancy/wiki/Nancy-and-Validation
标签: model-binding nancy request-validation