ASP.NET MVC 2 - Implementing custom Metadata and Validator Providers

好久不见. 提交于 2020-01-02 07:51:11

问题


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.


回答1:


Here's an example validator provider, using Enterprise Library:

http://bradwilson.typepad.com/blog/2009/10/enterprise-library-validation-example-for-aspnet-mvc-2.html

The metadata sample is coming soon.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!