模型验证与NancyFX [英] Model validation with NancyFX

查看:97
本文介绍了模型验证与NancyFX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的习惯的ASP.NET MVC的方法:用相应属性注释的模式,MVC不会对其进行验证和更新ModelState.Errors,ModelState中可在视图中,因此有可能显示错误的用户

我还没有发现信息维基究竟应该为NancyFX完成。在来源中我可以看到南​​希试图使用规则,但如何申请正确的视图显示故障?

修改:问题是有关南希0.9,按@的codeJunkie 0.10将申请变更为

解决方案

在当前标签的版本(0.9)我们没有任何内置的模型验证的支持。然而,随着挂起(最有可能在本周末)0.10版中,我们增加了对模型验证,并即将发运的NuGet包使用任何数据注释或流畅的验证。

主分支包含一个示范项目,展示了如何使用它们<一个href="https://github.com/NancyFx/Nancy/tree/master/src/Nancy.Demo.Validation">https://github.com/NancyFx/Nancy/tree/master/src/Nancy.Demo.Validation

当然,验证的东西是可扩展的,你可以提供自己的实现你自己的选择的验证框架。南希核心只包含一小部分的扩展点,然后将实际实现发运作为单独nugets。

0.10版本将包含允许创建基于模型的客户端验证的第一基石。不过,0.10版本将的没有的包含实际的客户端验证的东西,但挂钩提取验证信息是存在的,如本示例模块

<一个href="https://github.com/NancyFx/Nancy/blob/master/src/Nancy.Demo.Validation/ProductsModule.cs#L16">https://github.com/NancyFx/Nancy/blob/master/src/Nancy.Demo.Validation/ProductsModule.cs#L16

希望这有助于!

I'm really get used with ASP.NET MVC approach: annotate model with corresponding attributes, MVC does validate it and updates ModelState.Errors, ModelState is available on View, so it is possible to show errors to user.

I haven't found information on wiki how exactly it should be done for NancyFX. In sources I can see that Nancy trying to use Rules, but how to apply correctly and show failures on Views?

EDIT: Question is relevant to Nancy 0.9, according to @TheCodeJunkie 0.10 will apply changes for that.

解决方案

In the current tagged release (0.9) we do not have any built in support for model validation. However with the pending (most likely this weekend) 0.10 release we are adding support for model validation and will be shipping nuget packages for using either data annotations or fluent validation.

The master branch contains a demo project that shows how to use them https://github.com/NancyFx/Nancy/tree/master/src/Nancy.Demo.Validation

Of course the validation stuff is extensible and you can provide your own implementations for the validation framework of your own choice. The Nancy core only contains a small set of extensibility points and then the actual implementations are shipped as separate nugets.

The 0.10 release will contain the first building blocks for allowing the creation of client-side validation based on your model. However, the 0.10 release will not contain the actual client side validation stuff, but the hooks to extract the validation information is there as shown in this sample module

https://github.com/NancyFx/Nancy/blob/master/src/Nancy.Demo.Validation/ProductsModule.cs#L16

Hope this helps!

这篇关于模型验证与NancyFX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆