With the preview 2 release of ASP.NET MVC 2, we now have base classes to implement our own custom providers for metadata and validation. Specifically, with ModelMetadataProvider and ModelValidatorProvider.
There isn't a lot of documentation on these yet (just released yesterday as a preview, so I'm neither surprised nor disappointed).
Has anyone gotten custom implementations of either of these working? A very simple example (metadata and validator for just "Required") would be great!
Perhaps a lot of people have the same idea, but I'd like to use IronRuby to inject the metadata, and I'm looking for any example to get started.
Thanks!
Edit: Sounds like Brad Wilson (of xUnit.net fame) has some blog posts coming for this exact thing! If he doesn't answer here, I'll create an answer with links when those posts are ready.
Edit2: Sankarsan Bose over at CodingNDesign also has posts on the subject. (ModelValidator at the moment). Including here for future reference.
Here's an example validator provider, using Enterprise Library:
The metadata sample is coming soon.
This article by Daniel Chambers seems to be a good read if you are interested in asp.net mvc model metadata and model validation topics.
http://www.digitallycreated.net/Blog/54/deep-inside-asp.net-mvc-2-model-metadata-and-validation
来源:https://stackoverflow.com/questions/1510459/asp-net-mvc-2-implementing-custom-metadata-and-validator-providers