I've recently read about the model validation capabilities of ASP.NET MVC which are all very cool until a certain point. What happens if the application doesn't know the data that it works with because it is all stored in DB and built together at runtime. Just like in Drupal, I'd like to be able to define custom types at runtime, and assign runtime validation rules as well. Obviously, the idea of assigning attributes to well established models is now gone. What else could be done ? I am thinking in terms of rules being stored as JSON objects in the DB fields or something like that.
+1
A:
Have you looked at the jquery validation plugin? One of the options you have there is to declare your UI validation in Javascript. For example for my contact page I have the following validation being used.
$(document).ready(function () {
$("#ContactForm").validate({
rules: {
Name: "required",
Email: {
required: true,
email: true
},
Subject: "required",
Message: "required"
}
});
});
This is a very baisc usage of the plugin.
Obviously you will still need some sort of backend validation, but for you UI this sounds ideal to your scenario.
Sayed Ibrahim Hashimi
2010-03-19 22:57:12
Thanks, I will try this one. I guess, this is what I needed. The only difference is that the JSON will be stored in a DB field, and the backend will have to somehow expose it to the JQuery listener. The first idea that coems to mind is something like a validation controller that returns JSON results to AJAX requests.
2010-03-20 11:46:03
OK, the content for rules is JSON so you could store that in the DB.
Sayed Ibrahim Hashimi
2010-03-20 14:55:13