NHibernate Validator and ASP.NET MVC 4 - asp.net-mvc

We're looking at upgrading a large-scale project currently implemented using ASP.NET MVC 2 with xVal providing the glue between NHibernate Validator and client-side validation.
When I was looking for resources on using the new "unobtrusive" client side validation used in MVC 3/4 with NHibernate Validator, I was only able to locate a single (and nearly 3 year-old) blog post about this.
Has anyone successfully used NHibernate Validator for client-side validation in MVC 3/4? If so, what has your experience been?

Although I don't have any experience directly with NHibernate, FluentValidation (a validation framework worth considering itself) has an MVC 3/4 adapter extension project which would serve as an excellent guide to creating an NHibernate Validator implementation.

So, i've never used NHibernate Validator, but consider to, because NHibernate Validator has a better perfomance than native MVC unobtrusive validator(MVC validator is totaly based on reflection, in case of NHibernate Validator reflection work happens at startup only).
In case of a large-scale project, i think it is better way.

Related

Where can I find a decent tutorial/explanation of using Castle Validators with ASP.NET MVC2?

Where can I find a decent tutorial/explanation of using Castle Validators with ASP.NET MVC2?
I want to go with Castle because I'm not fond of the fact that I can't test my POCOs using Data Annotations without copying the logic of grabbing the attributes and calling isValid on all of them. I'm much more fond of the fact that with Castle I can just call IsValid on the ValidatorRunner which I can instantiate in my tests. I might just forget about the built-in mvc2 validation framework and go with xVal. /shrug
These articles/screencast seems to be good:
ASP.NET MVC Auto Model Validation with xVal
Model-based Client-side Validation for ASP.NET MVC
Contact Form with ASP.NET MVC, Castle Validation, & fluentHtml
Hope that helps.

Which validation framework is better?

Does anyone have any recommendations for either of these validation ASP.Net MVC Validation frameworks?
xVal: http://xval.codeplex.com/
FluentValidation: http://fluentvalidation.codeplex.com/documentation
NHibernate.Validator
DataAnnotations
by the way: my project use sharp-architecture
This is a personal opinion, xVal and FluentValidation have there pro's and con's. NHibernate.Validator is lighter weight, and functions better if you are already using NHibernate as your schema loader. Then the obvious DataAnnotations is built into ASP.NET which is always something hard to resist.
Personally I use xVal for the built in jQuery validation.
If you're using MVC 2, DataAnnotations and an xVal-like client side validation is built in.
If you're using MVC 1, you can use xVal alongside DataAnnotations. In fact, xVal by itself won't do anything for you--it's just a technology to link a server-side validation framework like DataAnnotations to a client-side validation framework like jQuery validation.
We're using DataAnnotations + xVal on a project and it's worked out all right. We needed to make some changes to the DataAnnotationsModelBinder.

Validation Framework for a WPF app (using MVP) and ASP.NET MVC

I'm looking for a form validation framework that works best in both Windows (WPF using MVP) and Web (ASP.NET MVC).
I'm currently looking at three choices:
Enterprise Library Validation Application Block
http://www.codeplex.com/FluentValidation
http://validationframework.codeplex.com
I like Fluent Validation as it looks a lot cleaner. The others, though, have been around longer.
Any other recommendations?
In MVC apps I've found Fluent Validation very useful for more complex validations. DataAnnotations are often enough for simple validations in MVC.

Why ASP.NET MVC 2 will have its own client-side validation?

I am interested what are possible reasons that ASP.NET MVC 2 will have its own client-side validation instead of merging with xVal validation framework? Has someone from ASP.NET MVC team blogged about it?
They are providing a way to plug in some other library for client-side validation.
Haacked blog:
Client-Side Validation – ASP.NET MVC 2 includes the jQuery validation library to provide client-side validation based on the model’s validation metadata. It is possible to hook in alternative client-side validation libraries by writing an adapter which adapts the client library to the JSON metadata in a manner similar to the xVal validation framework.

How do you do validation in ASP.NET MVC RC?

Does ASP.NET MVC provide a standard validator functionality or do you have to create your own validation manually? If the latter, is there any third party validator available that you can use on ASP.NET MVC web applications?
Shortly after I posted this answer I found xval which is a validation framework for ASP.NET MVC.
ASP.NET MVC contains methods like Html.ValidationSummary() and Html.ValidationMessage(). These are updated automatically if you use TryUpdateModel. You could also validate manually and set the errormessages yourself. Here is an example of how use it.
David Hayden wrote an article over at www.codebetter.com describing a great way to handle validation. Of course xVal is an option but it's always great to have an understanding.
I implemented a variant of the code I found on Stephen Walther's blog. I use it with LINQ2SQL models by defining an IValidatedEntity interface that includes the GetRuleViolations() method and implementing the partial OnValidate method that calls GetRuleViolations() and throws a custom exception if the number of violations is non-zero. In the controller, this fires on SubmitChanges for the data context. If I get an exception I requery the model via the GetRuleViolations() method to build model errors to pass back to the view.
You can also checkout the .net validation framework. Its a rules framework that lets you create validators, apply the validators to rules, attach rules to your model, and check those rules at runtime on both the client and server. It provides flexible ways to configure rules - making heavy use of linq for both fluent and strongly typed configuration. It also provides extensibility points to create your own client script generators and rules.
The framework leverages the MVC RC HtmlHelpers and default conventions.
If you download the latest source you can see an example of the framework working in the SplitBranch -> QSAspMvc quickstart project. Its still being actively developed.

Resources