React.js mixed with asp.net MVC for validation - asp.net-mvc

I am an experienced .net developer and I am very competent using MVC. I have only just read up a little on react.js today and would like to try and get more into it.
Are there any .net MVC developers or there that have mixed a project up with MVC with good results? Most notably to do with validation.
Normally my C# classes have validation attributes on them. And I can mess around with model state errors to do more custom stuff server side.
How would you mix react validation with MVC? Or can it not be done?
EDIT
Is there anyway to validate in React using the MVC attributes to save duplication of validation?

I would recommend having your validation rules server-side, then passing a json object to the client with those validation rules. On the client, you can then create logic to validate these rules, and then once the form is submitted you can run the server-side validation rules and pass back any failed validation to the client.

Related

What advantages does Mvc jquery validation offer?

What advantages, if any, does MVC jQuery Validation offer over the built-in MVC client validation?
I've used the built-in validation and am just curious as to if I'm missing anything or not.
How about customisation? I'm sure not everything is covered with the standard validators.
For example, our products are meant for people over 14yo so it's be nice to validate that client side rather than tie the server up with silly requests.
You can then share this and have a standard way of validating DOB.
MVC jQuery validation is done on the front end (client side), without submitting data to the controller (Server side). So it can save you some bandwidth/processing.
If you have a slow or overloaded server, users will get a quicker response to validation errors this way as well.
Server side validation is essential/required since it makes sure you are getting good data before you save it. The client side is nice to have, but shouldn't be all you have since its possible to bypass.

Form input validation options in ASP.NET MVC 1.0+

A number of questions have been asked on this topic before, but since ASP.NET MVC is moving quite fast I wanted to re-ask the question:
What would you recommend for providing form input validation in ASP.NET MVC?
Requirements:
Server-side checking
Client-side (JavaScript) checking
Should cover the basics such as mandatory fields, numeric range validation, regex validation
(So basically all (or most) of the stuff that the ASP.NET WebForms validation controls do)
Current options seem to be:
Validator Toolkit on CodePlex
Jumping to ASP.NET MVC 2 Preview 1 (Our application is for internal use and go-live is in 6 months, so we might be comfortable using the preview)
xVal should be good choice in your case.
I would use DataAnnotations, is going to be a part of MVC but can be compiled and used in 1.0.
http://www.asp.net/learn/mvc/tutorial-39-cs.aspx
/M
FluentValidation also has an MVC component, however it doesn't do the client side of things. Ideally this could be integrated with xVal.

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