I have an application who use ASP.NET MVC and KnockoutJS for the MVVM part. The server bind the data to the server by JSON. The client treat data and make a standard POST callback after that.
I have now to handle some business logic like :
- The property1 must be superior to 10 if property2 == "FOOBAR"
- The property2 must be != ""
Etc etc... (there is a lot of conditions I have to handle)
So, to make things simpler, is it possible to avoid code duplicate between the server side code (C#) and the client side (JS) ? The idea would be to define the validation rules at one place (using Data Annotations maybe) and use these rules to generate the JS code (for client side validation) or the C# code (for the server side validation).
Thanks by advance !