Now I use validation based on custom DataAnnotation attributes and DataAnnotationsModelValidatorProvider. Is fluent validation more fluent? :) Can it replace the DataAnnotations completely?
Sad answer is no. There are several validation rules in DataAnnotations that are currently not inforced in FluentValidation. That said, server-side implementing the same validations is a somewhat easy task, but having to implement them client side as well is a pain.
I know they are - and have been - working on a new version of FluentValidation that should be out soon, that adds support for more validations including custom ones (client side)
Related
When we are using EF (f.e.) via MVC, we can use ModelState.IsValid to detect a model can pass DataAnnotations metadata or not. But how can I use DataAnnotations metadata in a desktop (win-forms / wpf) application?
More:
In fact, I want to create an object same as ModelState (a dictionary that can save properties and messages associated with each). Then, wrap the DAL by a validation-layer, in VL use metadata to validate models, that the VL can be used in any project. I know I should use reflector, but I haven't any experience. Thanks to any help and suggestion.
If you are using EF 4.1/4.1 dbcontext, it has a built in validation API that can check Data Annotation rules as well as IValidatableObject.Validate. I'm not quite sure that I understand your goal, but if it is to have the validation in the data layer then you can just use what's built in. (Here's an overview http://msdn.microsoft.com/en-us/data/gg193959).
If you want your own validator that is separate from the data layer, then look at the System.ComponentModel.DataAnnotations namespace for methods and other logic you can leverage to do your own validation.
I am new to MVC.Just would like to start do some business logic to enforce validation.Is there any simple example to understand how to apply validation?
Check this out http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
This is an out of the box solution for validation on ASP.NET MVC.
You can use DataAnnotation validation support built-into the .NET Framework.
Please refer link text
for further clarifications.Moreover you can integrate EntLib or other validation library in ASP.MVC framework.
Happy coding.
I'm using ASP.NET MVC 2, DataAnnotation and MicrosoftMvcValidation.js for validation. I have two forms in my view..is there a way to use Validation Group for client side validation (like in ASP.NET Webforms).
thanks
The example I've seen with the nerd dinner (http://www.asp.net/mvc/videos/what-is-aspnet-mvc-80-minute-technical-video-for-developers-building-nerddinner) uses a partial class to modify the dinner model by adding validation to specific elements. This way validation can be handled at the server level but without server controls.
But... you can still use the validation controls with asp.net mvc if that's what you mean.
Did you mean to show summary of error(s)? If so you can use HTML helper for validation summary, like Html.ValidationSummary(...).
Hope this helps!
I'd like to use the new client side validation features in MVC 2 but I have a particular view that just has a couple textboxes on it and I don't want to create a strongly typed model for it. Can someone describe how to leverage the validation goodness in MVC 2 w/o a strongly typed model?
I don’t think it can be done as client side validation uses Data Annotations in the System.ComponentModel.DataAnnotations namespace. To my knowledge you have to bind this to an object. I would suggest looking at a jquery solution.
We've used the Validation Block of MS Enterprise Library for some time with great success in conjunction with custom DALs but we've recently started using the Entity Framework and can't get the Validation Block to work with it. The objects are dynamically created in EF and putting attributes on top of them will simply get wiped out when the models are re-genned.
Can these two co-exist? If not, does anyone have any recommendations for what validation library/simple rules engine would be a good candidate to use along with EF?
Thank you.
You need a validator which supports a "buddy class" (like this example for Dynamic Data). This seems to be a work in progress for VAB. I can't find an example of anyone actually using it yet, but it might work.
Validation Application Block supports the concept of configuration based validation. This way you can separate your generated domain entities from validation. You can use the Enterprise Library configuration tool for this. Simply right-click on your configuration file and start adding validation configuration.
I advise you to read the VAB Hands on Lab document (ValidationHOL.pdf) which is included in the Hands On Lab download. After reading that document, read this article. It explains how to integrate VAB with Entity Framework.
Good luck.