Is there a way to have the same kind of client-side validation in MVC 3 without being able to set the validation at the viewmodel level? I have two requirements that are preventing me from adding my validation at the viewmodel level. I'd like to be able to have the same kind of "built-in" validation but without changing the viewmodel or controller code. I'd like to be able to change, turn on/off, validation at the view level post-deployment. Ideally I'd like to be able to edit the view mark-up without writing and maintaini开发者_如何转开发ng mountains of my own JavaScript.
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
This may help ya, only validation on the client though so not really ideal.
You could create your own TypeDescriptionProvider which will allow to augment your viewmodel at runtime.
Based on this code sample (XmlMetadataTypeDescriptor, XmlMetadataTypeDescriptionProvider) you should be able to:
- Augment viewmodel using external xml which contains validation attributes.
Turn on validation with
TypeDescriptor.AddProvider
and turn it off with:
TypeDescriptor.RemoveProvider
Update
For more information you can read great article: "Understanding the TypeDescriptor: A Metadata Engine for Designtime Code".
精彩评论