Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model validation with NancyFX

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.

like image 418
Alexander Beletsky Avatar asked Feb 10 '12 09:02

Alexander Beletsky


1 Answers

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!

like image 115
TheCodeJunkie Avatar answered Sep 30 '22 21:09

TheCodeJunkie